﻿Imports ICtagControl.frmStartCompleteBase

Public Class clsDbEquipMat

    Private Sub SolveNull(ByRef dt As DataTable)
        Dim i As Integer
        'Dim isNull As Boolean = True
        'For Each dr As DataRow In dt.Rows
        '    For i = 0 To dt.Columns.Count - 1
        '        If IsDBNull(dr(i)) Then
        '            dr(i) = String.Empty
        '        ElseIf Not String.IsNullOrEmpty(dr(i).ToString) Then
        '            isNull = False
        '        End If
        '    Next
        '    If isNull Then
        '        dr.Delete()
        '    End If
        'Next
        'dt.AcceptChanges()

        If dt.Rows.Count >= 2 Then
            For i = 0 To dt.Columns.Count - 1
                If IsDBNull(dt.Rows(0)(i)) Then
                    dt.Rows(0)(i) = dt.Rows(1)(i)
                End If
            Next
        End If
        If dt.Rows.Count >= 1 Then
            For i = 0 To dt.Columns.Count - 1
                If IsDBNull(dt.Rows(0)(i)) Then
                    dt.Rows(0)(i) = String.Empty
                End If
            Next

        End If
    End Sub



    Private Function SqlCondCond(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                ByVal szTable As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  '' AS END_TIME, '' AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select
        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{1}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{1}' "
        szSql &= "  AND IS_CONDITION=TRUE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") CND  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{1}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON CND.LOT_NO2=SV2.LOT_NO "

        SqlCondCond = String.Format(szSql, szTable, szLotNo, szEquipID)
    End Function

    Private Function SqlCondCom(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                ByVal szTable As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  '' AS END_TIME, '' AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select
        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{1}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE IS_CONDITION=FALSE "
        If Not String.IsNullOrEmpty(szEquipID) Then
            szSql &= "  AND EQUIP_ID='{2}' "
        End If
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") MAT  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{1}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON MAT.LOT_NO2=SV2.LOT_NO "

        SqlCondCom = String.Format(szSql, szTable, szLotNo, szEquipID)
    End Function

    Private Function SqlCondLastTime(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                      ByVal szTable As String, ByVal szLastTable As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select
        'szSql &= String.Format("FROM MAT.{0} SAV ", szLastTable)
        'szSql &= String.Format("FULL OUTER JOIN MAT.{0} MAT ", szTable)
        'szSql &= "ON SAV.LOT_NO='" & szLotNo & "' "
        'szSql &= "WHERE MAT.EQUIP_ID='" & szEquipID & "' "
        'szSql &= "ORDER BY SAV.SYS_CMD_ID DESC, MAT.SYS_CMD_ID DESC "
        'szSql &= "LIMIT 1 "

        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{2}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{2}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SAV  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT CAST('{2}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{1} "
        szSql &= "  WHERE IS_CONDITION=FALSE "
        If Not String.IsNullOrEmpty(szEquipID) Then
            szSql &= "  AND EQUIP_ID='{3}' "
        End If
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") MAT  "
        szSql &= "ON MAT.LOT_NO2=SAV.LOT_NO2 "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{1} "
        szSql &= "  WHERE LOT_NO='{2}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON SV2.LOT_NO=SAV.LOT_NO2 "

        SqlCondLastTime = String.Format(szSql, szLastTable, szTable, szLotNo, szEquipID)
    End Function

    Private Function SqlCondLastTime2(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                      ByVal szTable As String, ByVal szLastTable1 As String, ByVal szLastTable2 As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select
        'szSql &= String.Format("FROM MAT.{0} SAV ", szLastTable)
        'szSql &= String.Format("FULL OUTER JOIN MAT.{0} MAT ", szTable)
        'szSql &= "ON SAV.LOT_NO='" & szLotNo & "' "
        'szSql &= "WHERE MAT.EQUIP_ID='" & szEquipID & "' "
        'szSql &= "ORDER BY SAV.SYS_CMD_ID DESC, MAT.SYS_CMD_ID DESC "
        'szSql &= "LIMIT 1 "

        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{3}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{3}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SA1  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT CAST('{3}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{1} "
        szSql &= "  WHERE LOT_NO='{3}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SA2  "
        szSql &= "ON SA2.LOT_NO2=SA1.LOT_NO2 "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT CAST('{3}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{2} "
        szSql &= "  WHERE IS_CONDITION=FALSE "
        If Not String.IsNullOrEmpty(szEquipID) Then
            szSql &= "  AND EQUIP_ID='{4}' "
        End If
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") MAT  "
        szSql &= "ON MAT.LOT_NO2=SA1.LOT_NO2 "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{2} "
        szSql &= "  WHERE LOT_NO='{3}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON SV2.LOT_NO=SA1.LOT_NO2 "

        SqlCondLastTime2 = String.Format(szSql, szLastTable1, szLastTable2, szTable, szLotNo, szEquipID)
    End Function

    Private Function SqlCondLot(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                      ByVal szTable As String, ByVal szLastTable As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  '' AS END_TIME, '' AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select

        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{2}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{2}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SAV  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{1} "
        szSql &= "  WHERE LOT_NO='{2}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON SV2.LOT_NO=SAV.LOT_NO2 "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT CAST('{2}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{1} "
        szSql &= "  WHERE IS_CONDITION=FALSE "
        If Not String.IsNullOrEmpty(szEquipID) Then
            szSql &= "  AND EQUIP_ID='{3}' "
        End If
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") MAT  "
        szSql &= "ON MAT.LOT_NO2=SAV.LOT_NO2 "


        SqlCondLot = String.Format(szSql, szLastTable, szTable, szLotNo, szEquipID)
    End Function

    Private Function SqlCondFttFlg(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szProcCD As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus, ByVal szTable As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  '' AS END_TIME, '' AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select

        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{1}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE IS_CONDITION=FALSE "
        If Not String.IsNullOrEmpty(szEquipID) Then
            szSql &= "  AND EQUIP_ID='{2}' "
        End If
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") MAT  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{1}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON SV2.LOT_NO=MAT.LOT_NO2 "

        Dim i As Integer
        For i = 0 To 2
            szSql &= "FULL OUTER JOIN ( "
            szSql &= "  SELECT * FROM MAT.L_EQUIP_MAT_FT_TEST" & i.ToString & " "
            szSql &= "  WHERE LOT_NO='{1}' "
            szSql &= "  AND IS_CONDITION=FALSE "
            szSql &= "  ORDER BY SYS_CMD_ID DESC "
            szSql &= "  LIMIT 1 "
            szSql &= ") P" & i.ToString & " "
            szSql &= "ON P" & i.ToString & ".LOT_NO=MAT.LOT_NO2  "
        Next
        'szSql &= "  LIMIT 1 "


        SqlCondFttFlg = String.Format(szSql, szTable, szLotNo, szEquipID)
    End Function

    Private Function SqlCondFtt(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szProcCD As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus, ByVal szTable As String) As String
        Dim szSql As String = ""
        Select Case Status
            Case TagProcessStatus.Ready
                If szEquipID.Equals(szOldEquipID) Then
                    szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                    szSql &= ",  TO_CHAR(SV2.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.TOTAL_OPT AS END_OPT "
                Else
                    szSql &= ",  '' AS BEGIN_TIME, '' AS BEGIN_OPT "
                    szSql &= ",  '' AS END_TIME, '' AS END_OPT "
                End If
            Case TagProcessStatus.Processing
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  '' AS END_TIME, '' AS END_OPT "
            Case TagProcessStatus.ManufComplete
                szSql &= ",  TO_CHAR(SV2.BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, SV2.BEGIN_OPT AS BEGIN_OPT "
                szSql &= ",  TO_CHAR(SV2.COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, SV2.COMPLETE_OPT AS END_OPT "
        End Select

        szSql &= "FROM ( "
        szSql &= "  SELECT CAST('{1}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.L_EQUIP_MAT_FT_BARIN "
        szSql &= "  WHERE LOT_NO='{1}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SAV  "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT CAST('{1}' AS TEXT) AS LOT_NO2, "
        szSql &= "  * FROM MAT.{0} "
        szSql &= "  WHERE IS_CONDITION=FALSE "
        If Not String.IsNullOrEmpty(szEquipID) Then
            szSql &= "  AND EQUIP_ID='{2}' "
        End If
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") MAT  "
        szSql &= "ON MAT.LOT_NO2=SAV.LOT_NO2 "
        szSql &= "FULL OUTER JOIN ( "
        szSql &= "  SELECT * FROM MAT.{0} "
        szSql &= "  WHERE LOT_NO='{1}' "
        szSql &= "  AND IS_CONDITION=FALSE "
        szSql &= "  ORDER BY SYS_CMD_ID DESC "
        szSql &= "  LIMIT 1 "
        szSql &= ") SV2  "
        szSql &= "ON SV2.LOT_NO=SAV.LOT_NO2 "

        Dim i As Integer
        For i = 0 To 2
            szSql &= "FULL OUTER JOIN ( "
            szSql &= "  SELECT * FROM MAT.L_EQUIP_MAT_FT_TEST" & i.ToString & " "
            szSql &= "  WHERE LOT_NO='{1}' "
            szSql &= "  AND IS_CONDITION=FALSE "
            szSql &= "  ORDER BY SYS_CMD_ID DESC "
            szSql &= "  LIMIT 1 "
            szSql &= ") P" & i.ToString & " "
            szSql &= "ON P" & i.ToString & ".LOT_NO=SAV.LOT_NO2  "
        Next
        'szSql &= "  LIMIT 1 "


        SqlCondFtt = String.Format(szSql, szTable, szLotNo, szEquipID)
    End Function

    Public Function GetEquipMatCom(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                   ByVal Status As TagProcessStatus, ByVal szTable As String,
                                              ByVal ParamArray szQty() As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        For Each szItem As String In szQty
            szSql &= String.Format("SV2.{0}, ", szItem)
        Next
        szSql &= "  MAT.EQUIP_ID "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, szTable)

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatCom = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatCom = dt
        End If
    End Function

    ''' <summary>
    ''' 一般治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatCom(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                      ByVal szSysEquipID As String, ByVal szEquipNo As String, ByVal szProcCD As String,
                                      ByVal dtEquipMat As DataTable, ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                      ByVal szTable As String, ByVal dtHeader As DataTable,
                                      Optional ByVal szMemoCap1 As String = "", Optional ByVal szMemo1 As String = "",
                                      Optional ByVal szMemoCap2 As String = "", Optional ByVal szMemo2 As String = "") As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        szSql = String.Format("INSERT INTO MAT.{0} ( ", szTable)
        szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
        szSql &= "  BEGIN_TIME, BEGIN_OPT "
        If Not String.IsNullOrEmpty(szMemoCap1) Then
            szSql &= String.Format("  ,{0} ", szMemoCap1)
        End If
        If Not String.IsNullOrEmpty(szMemoCap2) Then
            szSql &= String.Format("  ,{0} ", szMemoCap2)
        End If
        szSql &= ") "
        szSql &= "VALUES ( "
        szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                               "'{5}', '{6}'",
                              szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                              dte, szBeginOpt)
        If Not String.IsNullOrEmpty(szMemoCap1) Then
            szSql &= String.Format("  ,'{0}' ", szMemo1)
        End If
        If Not String.IsNullOrEmpty(szMemoCap2) Then
            szSql &= String.Format("  ,'{0}' ", szMemo2)
        End If
        szSql &= ")"

        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        UpdateEquipMatCom = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        End If

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatTape(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   MAT.TAPE_TAPE, MAT.TAPE_TAPE_LOT, MAT.TAPE_TAPE_LT, "
        szSql &= "   SV2.WAFER_COMPLETE, "
        szSql &= "   SV2.TAPE_WAFER_D, SV2.TAPE_WAFER_T, SV2.TAPE_OF_ANGLE "

        szSql &= SqlCondCom(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_TAPE")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatTape = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatTape = dt
        End If
    End Function

    ''' <summary>
    ''' テープ治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatTape(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_TAPE "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TAPE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  TAPE_TAPE, TAPE_TAPE_LOT, TAPE_TAPE_LT, "
            szSql &= "  TAPE_WAFER_D, TAPE_WAFER_T, TAPE_OF_ANGLE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TAPE_TAPE"), .Item("TAPE_TAPE_LOT"), .Item("TAPE_TAPE_LT"),
                                  .Item("TAPE_WAFER_D"), .Item("TAPE_WAFER_T"), .Item("TAPE_OF_ANGLE"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTape = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TAPE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  TAPE_TAPE, TAPE_TAPE_LOT, TAPE_TAPE_LT, "
            szSql &= "  TAPE_WAFER_D, TAPE_WAFER_T, TAPE_OF_ANGLE, "
            szSql &= "  WAFER_COMPLETE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', " &
                                   "'{12}', '{13}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TAPE_TAPE"), .Item("TAPE_TAPE_LOT"), .Item("TAPE_TAPE_LT"),
                                  .Item("TAPE_WAFER_D"), .Item("TAPE_WAFER_T"), .Item("TAPE_OF_ANGLE"),
                                  .Item("WAFER_COMPLETE"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTape = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveTape(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTape() As String, ByVal szWafer As String) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_TAPE "
        szSql &= "SET "
        szSql &= "  TAPE_TAPE ='" & szTape(0) & "', "
        szSql &= "  TAPE_TAPE_LOT ='" & szTape(1) & "', "
        szSql &= "  TAPE_TAPE_LT ='" & szTape(2) & "', "
        'szSql &= "  TAPE_OF_ANGLE ='" & szTape(3) & "', "
        szSql &= "  WAFER_COMPLETE ='" & szWafer & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function SaveWaferQty(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szWafer As String, ByVal szTable As String) As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  WAFER_COMPLETE ='" & szWafer & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function


    Public Function GetEquipMatBarCode(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SAV.WAFER_COMPLETE AS WAFER_INPUT, SV2.WAFER_COMPLETE, "
        szSql &= "   SV2.BARCODE_SELF_CHECK "

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_BARCODE", "L_EQUIP_MAT_TAPE")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatBarCode = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatBarCode = dt
        End If
    End Function

    ''' <summary>
    ''' テープＵＶ治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatBarCode(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_BARCODE "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_BARCODE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  BARCODE_SELF_CHECK, "
            szSql &= "  WAFER_INPUT, WAFER_COMPLETE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}', " &
                                   "'{8}', '{9}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BARCODE_SELF_CHECK"),
                                  .Item("WAFER_INPUT"), .Item("WAFER_COMPLETE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBarCode = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatDicing(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                      ByVal Status As TagProcessStatus, ByVal Proc_Table As String, ByVal Pre_Proc_TABLE As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   MAT.DICING_BLADE, '' AS DICING_SELF_CHECK, "
        szSql &= "   SAV.WAFER_COMPLETE AS WAFER_INPUT, SV2.WAFER_COMPLETE, "
        szSql &= "   SV2.DICING_CHIP_SIZE, SV2.DICING_WAFER_D, SV2.DICING_WAFER_T "

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, Proc_Table, Pre_Proc_TABLE)

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatDicing = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatDicing = dt
        End If
    End Function

    ''' <summary>
    ''' ダイシング治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatDicing(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                         ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_DICING "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_LASER_DICING( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  LASER_DICING_WAFER_D, LASER_DICING_WAFER_T, "
            'szSql &= "  WAFER_COMPLETE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}',  " &
                                   "'{7}', '{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("LASER_DICING_WAFER_D"), .Item("LASER_DICING_WAFER_T"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatDicing = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_LASER_DICING( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  LASER_DICING_WAFER_D, LASER_DICING_WAFER_T, "
            szSql &= "  WAFER_INPUT, "
            szSql &= "  WAFER_COMPLETE, "
            szSql &= "  LASER_DICING_RECIP_CHECK , LASER_DICING_SELF_CHECK,"
            szSql &= "  CASE_NO , LASER_DICING_DUMMY_JYOKEN , LASER_DICING_DUMMY_CHECK,"
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', " &
                                   "'{8}', " &
                                   "'{9}', '{10}', " &
                                   "'{11}', '{12}', '{13}' ," &
                                   "'{14}', '{15}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("LASER_DICING_WAFER_D"), .Item("LASER_DICING_WAFER_T"),
                                  .Item("WAFER_INPUT"),
                                  .Item("WAFER_COMPLETE"),
                                  .Item("LASER_DICING_RECIP_CHECK"), .Item("LASER_DICING_SELF_CHECK"),
                                  .Item("CASE_NO"), .Item("LASER_DICING_DUMMY_JYOKEN"), .Item("LASER_DICING_DUMMY_CHECK"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatDicing = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatTapeUv(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SAV.WAFER_COMPLETE AS WAFER_INPUT, SV2.WAFER_COMPLETE, "
        szSql &= "   SV2.TAPE_UV_SELF_CHECK,"
        szSql &= "   SAV.DICING_CASE_NO AS DICING_CASE_NO"

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_TAPE_UV", "L_EQUIP_MAT_DICING")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatTapeUv = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatTapeUv = dt
        End If
    End Function

    ''' <summary>
    ''' テープＵＶ治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatTapeUv(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_TAPE_UV "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TAPE_UV( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  CASE_NO, TAPE_UV_SELF_CHECK, "
            szSql &= "  WAFER_INPUT, "
            szSql &= "  WAFER_COMPLETE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', " &
                                   "'{8}', " &
                                   "'{9}', '{10}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("CASE_NO"), .Item("TAPE_UV_SELF_CHECK"),
                                  .Item("WAFER_INPUT"),
                                  .Item("WAFER_COMPLETE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTapeUv = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveCheckWafer(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szWafer As String, ByVal szCheck As String, ByVal szTable As String, ByVal szSelfCheck As String) As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= String.Format("  {0} ='{1}', ", szSelfCheck, szCheck)
        szSql &= "  WAFER_COMPLETE ='" & szWafer & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function SaveWafer(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szWafer As String, ByVal szTable As String) As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  WAFER_COMPLETE ='" & szWafer & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function


    Public Function GetEquipMatDicChk(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SAV.WAFER_COMPLETE AS WAFER_INPUT, SV2.WAFER_COMPLETE, "
        szSql &= "   SV2.DICCHK_OF_ANGLE, SV2.DICCHK_CHECK_SPEC, "
        szSql &= "   SV2.DICCHK_CHIP_NAME, SV2.DICCHK_CHIP_POS, SV2.DICCHK_CHECK_SPEC_M "

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_DIC_CHK", "L_EQUIP_MAT_TAPE_UV")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatDicChk = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatDicChk = dt
        End If
    End Function

    ''' <summary>
    ''' ダイシング治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatDicChk(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                         ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_DIC_CHK "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_DIC_CHK( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  DICCHK_OF_ANGLE, DICCHK_CHECK_SPEC, "
            szSql &= "  DICCHK_CHIP_NAME, DICCHK_CHIP_POS, DICCHK_CHECK_SPEC_M, "
            'szSql &= "  WAFER_COMPLETE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("DICCHK_OF_ANGLE"), .Item("DICCHK_CHECK_SPEC"),
                                  .Item("DICCHK_CHIP_NAME"), .Item("DICCHK_CHIP_POS"), .Item("DICCHK_CHECK_SPEC_M"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatDicChk = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_DIC_CHK( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  DICCHK_OF_ANGLE, DICCHK_CHECK_SPEC, "
            szSql &= "  DICCHK_CHIP_NAME, DICCHK_CHIP_POS, DICCHK_CHECK_SPEC_M, "
            szSql &= "  WAFER_INPUT, "
            szSql &= "  WAFER_COMPLETE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', '{9}', " &
                                   "'{10}', " &
                                   "'{11}', " &
                                   "'{12}', '{13}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("DICCHK_OF_ANGLE"), .Item("DICCHK_CHECK_SPEC"),
                                  .Item("DICCHK_CHIP_NAME"), .Item("DICCHK_CHIP_POS"), .Item("DICCHK_CHECK_SPEC_M"),
                                  .Item("WAFER_INPUT"),
                                  .Item("WAFER_COMPLETE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatDicChk = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    ''' <summary>
    ''' 仕掛情報の保存
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateL_LotData(ByVal tagDat As TagData) As Integer
        DBacs.BeginTransaction()

        Dim strQFlg As String = "0"
        Dim strTestFlg As String = "0"
        Dim strfCheckFlg As String = "0"

        Dim szSql As String = ""
        With tagDat

            strQFlg = If(.fQflag, 1, 0)
            strTestFlg = If(.fTestflag, 1, 0)
            strfCheckFlg = If(.fCheckflag, 1, 0)

            szSql &= "UPDATE PER.L_TAG_LOTDATA "
            szSql &= "SET "
            szSql &= "  WAFER_LOTNO ='" & .szDifLotNo & "', "
            szSql &= "  STATUS     = " & .Status & ", "
            szSql &= "  EQUIPNO      ='" & .szEquipID & "', "
            szSql &= "  KOUTEI_CODE      ='" & .szProcsCD & "', "
            szSql &= "  INVNUM     = " & .iInput & ", "
            szSql &= "  COMPNUM    = " & .iFinish & ", "
            szSql &= "  BADNUM     = " & .iFailed & ", "
            szSql &= "  FRAMENUM   = " & .iFrame & ", "
            szSql &= "  BADMARKNUM = " & .iCross & ", "
            szSql &= "  BADMARK_FRAMENUM = " & .iCrossFrm & ", "
            szSql &= "  Q_FLG       = '" & strQFlg & "', "
            szSql &= "  TEST_FLG    = '" & strTestFlg & "', "
            szSql &= "  CHECK_FLG   = '" & strfCheckFlg & "', "
            szSql &= "  HOLDSTATUS = " & .OnHoldSt & " ,"
            '>>2018/1/30 佐川 キャリア交換対応
            szSql &= "  CONTAINER1 = '" & .container1 & "' , "
            szSql &= "  CONTAINER2 = '" & .container2 & "' , "
            szSql &= "  CONTAINER3 = '" & .container3 & "' , "
            szSql &= "  CONTAINER4 = '" & .container4 & "' , "
            szSql &= "  CONTAINER5 = '" & .container5 & "' "
            '<<2018/1/30 佐川 キャリア交換対応
            '>>2018/2/13 大賀 サンプル数量対応
            szSql &= "  , PLT_EQUIPNO = '" & .plateEquipNo & "' "
            '>>2018/2/13 大賀 サンプル数量対応
            '>>2018/2/19 大賀 No75 空チップ数量のl_tag_lotdata化
            szSql &= "  , EMPTY_CHIP_NUM = " & .emptyChipNum & " "
            '<<2018/2/19 大賀 No75 空チップ数量のl_tag_lotdata化
            '>>20180302 大賀 GroupKey入力時ウェハ枚数入力
            szSql &= "  , WAFER_NUM = " & .waferNum & " "
            '<<20180302 大賀 GroupKey入力時ウェハ枚数入力
            'ADD 苗  2018/1/24 BEGIN
            If .iDisposalFrmNum <> 999999 Then
                szSql &= " ,  DISPOSAL_FRAME_NUM = " & .iDisposalFrmNum & "  "
            End If
            'ADD 苗  2018/1/24 END
            szSql &= "WHERE LOT_NO  ='" & .szLotNo & "' "
        End With

        Dim cnt As Integer
        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        UpdateL_LotData = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function SaveDicChk(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szWafer As String,
                               ByVal szOfAngle As String, ByVal szChkSpec As String, ByVal szChipName As String, ByVal szChipPos As String, ByVal szCheckSpec As String) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_DIC_CHK "
        szSql &= "SET "
        szSql &= "  WAFER_COMPLETE ='" & szWafer & "', "
        szSql &= "  DICCHK_OF_ANGLE ='" & szOfAngle & "', "
        szSql &= "  DICCHK_CHECK_SPEC ='" & szChkSpec & "', "
        szSql &= "  DICCHK_CHIP_NAME ='" & szChipName & "', "
        szSql &= "  DICCHK_CHIP_POS ='" & szChipPos & "', "
        szSql &= "  DICCHK_CHECK_SPEC_M ='" & szCheckSpec & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function


    Public Function GetEquipMatDB(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        'szSql &= "SELECT SV2.CROSS_QTY, "
        'szSql &= "  MAT.DB_GUM_COLLET, MAT.DB_COLLET, MAT.DB_POCKET, MAT.DB_PIN, "
        'szSql &= "  MAT.DB_KOMA, MAT.DB_STAGE, MAT.DB_NOZZLE, "
        'szSql &= "  MAT.DB_PASTE, MAT.DB_PASTE_LOT, MAT.DB_PASTE_LT, "
        'szSql &= "  MAT.DB_PASTE2, MAT.DB_PASTE_LOT2, MAT.DB_PASTE_LT2, "
        'szSql &= "  MAT.DB_SUBCHIP, "
        'szSql &= "  MAT.DB_FRAME_NAME, MAT.DB_FRAME_LOT, MAT.DB_FRM_YL, MAT.DB_FRAME_QTY, MAT.DB_FRAME_LT, "
        'szSql &= "  MAT.DB_FRAME_NAME2, MAT.DB_FRAME_LOT2, MAT.DB_FRM_YL2, MAT.DB_FRAME_QTY2, MAT.DB_FRAME_LT2, "
        'szSql &= "  MAT.DB_FRAME_NAME3, MAT.DB_FRAME_LOT3, MAT.DB_FRM_YL3, MAT.DB_FRAME_QTY3, MAT.DB_FRAME_LT3, "
        'szSql &= "  MAT.DB_FRAME_MARK, MAT.DB_CHIP_ARRANGE, MAT.DB_DIE_SIZE, MAT.DB_CURE "
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  MAT.DB_EQUIP_RECIPE, MAT.DB_WAFER_SUPPLY, MAT.DB_GRADE, "
        szSql &= "  MAT.DB_PASTE, MAT.DB_PASTE_CONTNUM, MAT.DB_PASTE_LOT, "
        szSql &= "  MAT.DB_PASTE2, MAT.DB_PASTE_CONTNUM2, MAT.DB_PASTE_LOT2, "
        szSql &= "  MAT.DB_FRAME_NAME, MAT.DB_FRAME_LOT, "
        szSql &= "  MAT.DB_FRAME_NAME2, MAT.DB_FRAME_LOT2, "
        szSql &= "  MAT.DB_FRAME_NAME3, MAT.DB_FRAME_LOT3, "
        szSql &= "  MAT.DB_FRAME_MARK, MAT.DB_CHIP_ARRANGE, "
        szSql &= "  MAT.SELF_CHECK, MAT.SELF_CHECK_QTY, MAT.WAFER_INPUT"
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_DB")
        'szSql &= SqlCondLot(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_DB", preTable)
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatDB = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatDB = dt
        End If
    End Function

    ''' <summary>
    ''' DB治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatDB(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                     ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                     ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                     ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                     ByVal szMemo As String, ByVal szPlanqty As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If
        ' 蘇州対応 2017/04/24 T.Yutaro Upd Start
        '製造条件を保存
        With dtEquipMat.Rows(1)
            'szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
            'szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            'szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
            'szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
            'szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
            'szSql &= "  DB_SUBCHIP, "
            'szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
            'szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
            'szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
            'szSql &= "  DB_FRAME_MARK, DB_CHIP_ARRANGE, DB_DIE_SIZE, DB_CURE, "
            'szSql &= "  BEGIN_TIME, BEGIN_OPT,  "
            'szSql &= "  DB_MEMO, DB_PLAN_QTY  "
            'szSql &= ") "
            'szSql &= "VALUES ( "
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " & _
            '                       "'{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', " & _
            '                       "'{12}', '{13}', '{14}', " & _
            '                       "'{15}', '{16}', '{17}', " & _
            '                       "'{18}', " & _
            '                       "'{19}', '{20}', '{21}', '{22}', '{23}', " & _
            '                       "'{24}', '{25}', '{26}', '{27}', '{28}', " & _
            '                       "'{29}', '{30}', '{31}', '{32}', '{33}', " & _
            '                       "'{34}', '{35}', '{36}', '{37}', " & _
            '                       "'{38}', '{39}', " & _
            '                       "'{40}', '{41}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("DB_GUM_COLLET"), .Item("DB_COLLET"), .Item("DB_POCKET"), .Item("DB_PIN"), .Item("DB_KOMA"), .Item("DB_STAGE"), .Item("DB_NOZZLE"), _
            '                      .Item("DB_PASTE"), .Item("DB_PASTE_LOT"), .Item("DB_PASTE_LT"), _
            '                      .Item("DB_PASTE2"), .Item("DB_PASTE_LOT2"), .Item("DB_PASTE_LT2"), _
            '                      .Item("DB_SUBCHIP"), _
            '                      .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"), .Item("DB_FRM_YL"), .Item("DB_FRAME_QTY"), .Item("DB_FRAME_LT"), _
            '                      .Item("DB_FRAME_NAME2"), .Item("DB_FRAME_LOT2"), .Item("DB_FRM_YL2"), .Item("DB_FRAME_QTY2"), .Item("DB_FRAME_LT2"), _
            '                      .Item("DB_FRAME_NAME3"), .Item("DB_FRAME_LOT3"), .Item("DB_FRM_YL3"), .Item("DB_FRAME_QTY3"), .Item("DB_FRAME_LT3"), _
            '                      .Item("DB_FRAME_MARK"), .Item("DB_CHIP_ARRANGE"), .Item("DB_DIE_SIZE"), .Item("DB_CURE"), _
            '                      dte, szBeginOpt, _
            '                      szMemo, szPlanqty)
            'szSql &= ")"
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  DB_EQUIP_RECIPE, DB_WAFER_SUPPLY, DB_GRADE, "
            szSql &= "  DB_PASTE, "
            szSql &= "  DB_FRAME_NAME, "
            szSql &= "  DB_FRAME_MARK, DB_CHIP_ARRANGE, SELF_CHECK, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', " &
                                   "'{9}', " &
                                   "'{10}', '{11}', '{12}', " &
                                   "'{13}', '{14}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("DB_EQUIP_RECIPE"), .Item("DB_WAFER_SUPPLY"), .Item("DB_GRADE"),
                                  .Item("DB_PASTE"),
                                  .Item("DB_FRAME_NAME"),
                                  .Item("DB_FRAME_MARK"), .Item("DB_CHIP_ARRANGE"), .Item("SELF_CHECK"),
                                  dte, szBeginOpt,
                                  szMemo, szPlanqty)
            szSql &= ")"
            ' 蘇州対応 2017/04/24 T.Yutaro Upd End
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatDB = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With
        ' 蘇州対応 2017/04/24 T.Yutaro Upd Start
        'szSql = ""
        'szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
        'szSql &= "SET "
        'szSql &= "  SYS_EQUIP_ID='{0}', "
        'szSql &= "  LOT_NO='" & szLotNo & "', "
        'szSql &= "  EQUIP_NO='{1}', "
        'szSql &= "  KOUTEI_CD='{2}', "
        'szSql &= "  DB_GUM_COLLET='{3}', "
        'szSql &= "  DB_COLLET='{4}', "
        'szSql &= "  DB_POCKET='{5}', "
        'szSql &= "  DB_PIN='{6}', "
        'szSql &= "  DB_KOMA='{7}', "
        'szSql &= "  DB_STAGE='{8}', "
        'szSql &= "  DB_NOZZLE='{9}', "
        'szSql &= "  DB_PASTE='{10}', "
        'szSql &= "  DB_PASTE_LOT='{11}', "
        'szSql &= "  DB_PASTE_LT='{12}', "
        'szSql &= "  DB_PASTE2='{13}', "
        'szSql &= "  DB_PASTE_LOT2='{14}', "
        'szSql &= "  DB_PASTE_LT2='{15}', "
        'szSql &= "  DB_SUBCHIP='{16}', "
        'szSql &= "  DB_FRAME_NAME='{17}', "
        'szSql &= "  DB_FRAME_LOT='{18}', "
        'szSql &= "  DB_FRM_YL='{19}', "
        'szSql &= "  DB_FRAME_QTY='{20}', "
        'szSql &= "  DB_FRAME_LT='{21}', "
        'szSql &= "  DB_FRAME_NAME2='{22}', "
        'szSql &= "  DB_FRAME_LOT2='{23}', "
        'szSql &= "  DB_FRM_YL2='{24}', "
        'szSql &= "  DB_FRAME_QTY2='{25}', "
        'szSql &= "  DB_FRAME_LT2='{26}', "
        'szSql &= "  DB_FRAME_NAME3='{27}', "
        'szSql &= "  DB_FRAME_LOT3='{28}', "
        'szSql &= "  DB_FRM_YL3='{29}', "
        'szSql &= "  DB_FRAME_QTY3='{30}', "
        'szSql &= "  DB_FRAME_LT3='{31}', "
        'szSql &= "  DB_FRAME_MARK='{32}', "
        'szSql &= "  DB_CURE='{33}', "
        'szSql &= "  BEGIN_TIME='{34}', "
        'szSql &= "  BEGIN_OPT='{35}' "
        'szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        'szSql &= "AND LOT_NO IN ('" & szLotNo & "', '') "
        'szSql &= "AND BEGIN_OPT = '' "
        'szSql &= "AND IS_DONE = False "
        'szSql &= "AND IS_CONDITION=FALSE "

        'With dtEquipMat.Rows(0)
        '    szSql = String.Format(szSql, _
        '                          szSysEquipID, szEquipNo, szProcCD, _
        '                          .Item("DB_GUM_COLLET"), .Item("DB_COLLET"), .Item("DB_POCKET"), .Item("DB_PIN"), .Item("DB_KOMA"), .Item("DB_STAGE"), .Item("DB_NOZZLE"), _
        '                          .Item("DB_PASTE"), .Item("DB_PASTE_LOT"), .Item("DB_PASTE_LT"), _
        '                          .Item("DB_PASTE2"), .Item("DB_PASTE_LOT2"), .Item("DB_PASTE_LT2"), _
        '                          .Item("DB_SUBCHIP"), _
        '                          .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"), .Item("DB_FRM_YL"), .Item("DB_FRAME_QTY"), .Item("DB_FRAME_LT"), _
        '                          .Item("DB_FRAME_NAME2"), .Item("DB_FRAME_LOT2"), .Item("DB_FRM_YL2"), .Item("DB_FRAME_QTY2"), .Item("DB_FRAME_LT2"), _
        '                          .Item("DB_FRAME_NAME3"), .Item("DB_FRAME_LOT3"), .Item("DB_FRM_YL3"), .Item("DB_FRAME_QTY3"), .Item("DB_FRAME_LT3"), _
        '                          .Item("DB_FRAME_MARK"), .Item("DB_CURE"), _
        '                         dte, szBeginOpt)
        'End With
        szSql = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
        szSql &= "SET "
        szSql &= "  SYS_EQUIP_ID='{0}', "
        szSql &= "  LOT_NO='" & szLotNo & "', "
        szSql &= "  EQUIP_NO='{1}', "
        szSql &= "  KOUTEI_CD='{2}', "
        szSql &= "  DB_EQUIP_RECIPE='{3}', "
        szSql &= "  DB_WAFER_SUPPLY='{4}', "
        szSql &= "  DB_GRADE='{5}', "
        szSql &= "  DB_PASTE='{6}', "
        szSql &= "  DB_PASTE_CONTNUM='{7}', "
        szSql &= "  DB_PASTE_LOT='{8}', "
        szSql &= "  DB_FRAME_NAME='{9}', "
        szSql &= "  DB_FRAME_LOT='{10}', "
        szSql &= "  DB_FRAME_MARK='{11}', "
        szSql &= "  DB_CHIP_ARRANGE='{12}', "
        szSql &= "  SELF_CHECK='{13}', "
        szSql &= "  WAFER_INPUT='{14}', "
        szSql &= "  BEGIN_TIME='{15}', "
        szSql &= "  BEGIN_OPT='{16}' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO IN ('" & szLotNo & "', '') "
        szSql &= "AND BEGIN_OPT = '' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "
        ' 蘇州対応 2017/04/24 T.Yutaro Upd End
        With dtEquipMat.Rows(0)
            szSql = String.Format(szSql,
                                  szSysEquipID, szEquipNo, szProcCD,
                                  .Item("DB_EQUIP_RECIPE"), .Item("DB_WAFER_SUPPLY"), .Item("DB_GRADE"),
                                  .Item("DB_PASTE"), .Item("DB_PASTE_CONTNUM"), .Item("DB_PASTE_LOT"),
                                  .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"),
                                  .Item("DB_FRAME_MARK"), .Item("DB_CHIP_ARRANGE"), .Item("SELF_CHECK"), .Item("WAFER_INPUT"),
                                 dte, szBeginOpt)
        End With

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
        UpdateEquipMatDB = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        ElseIf cnt = 0 Then
            '記録された詰範囲が存在しない場合
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
            szSql &= "SET "
            'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
            'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            szSql &= "AND IS_CONDITION=FALSE "

            DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            UpdateEquipMatDB = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
            ' 蘇州対応 2017/04/24 T.Yutaro Upd Start
            With dtEquipMat.Rows(0)
                'szSql = ""
                'szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
                'szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
                'szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
                'szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
                'szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
                'szSql &= "  DB_SUBCHIP, "
                'szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
                'szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
                'szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
                'szSql &= "  DB_FRAME_MARK, DB_CURE, "
                'szSql &= "  BEGIN_TIME, BEGIN_OPT "
                'szSql &= ") "
                'szSql &= "VALUES ( "
                'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " & _
                '                       "'{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', " & _
                '                       "'{12}', '{13}', '{14}', " & _
                '                       "'{15}', '{16}', '{17}', " & _
                '                       "'{18}', " & _
                '                       "'{19}', '{20}', '{21}', '{22}', '{23}', " & _
                '                       "'{24}', '{25}', '{26}', '{27}', '{28}', " & _
                '                       "'{29}', '{30}', '{31}', '{32}', '{33}', " & _
                '                       "'{34}', '{35}', " & _
                '                       "'{36}', '{37}'", _
                '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
                '                      .Item("DB_GUM_COLLET"), .Item("DB_COLLET"), .Item("DB_POCKET"), .Item("DB_PIN"), .Item("DB_KOMA"), .Item("DB_STAGE"), .Item("DB_NOZZLE"), _
                '                      .Item("DB_PASTE"), .Item("DB_PASTE_LOT"), .Item("DB_PASTE_LT"), _
                '                      .Item("DB_PASTE2"), .Item("DB_PASTE_LOT2"), .Item("DB_PASTE_LT2"), _
                '                      .Item("DB_SUBCHIP"), _
                '                      .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"), .Item("DB_FRM_YL"), .Item("DB_FRAME_QTY"), .Item("DB_FRAME_LT"), _
                '                      .Item("DB_FRAME_NAME2"), .Item("DB_FRAME_LOT2"), .Item("DB_FRM_YL2"), .Item("DB_FRAME_QTY2"), .Item("DB_FRAME_LT2"), _
                '                      .Item("DB_FRAME_NAME3"), .Item("DB_FRAME_LOT3"), .Item("DB_FRM_YL3"), .Item("DB_FRAME_QTY3"), .Item("DB_FRAME_LT3"), _
                '                      .Item("DB_FRAME_MARK"), .Item("DB_CURE"), _
                '                     dte, szBeginOpt)
                'szSql &= ")"
                szSql = ""
                szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
                szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
                szSql &= "  DB_EQUIP_RECIPE, DB_WAFER_SUPPLY, DB_GRADE, "
                szSql &= "  DB_PASTE, DB_PASTE_CONTNUM, DB_PASTE_LOT, "
                szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, "
                szSql &= "  DB_FRAME_MARK, DB_CHIP_ARRANGE, SELF_CHECK, WAFER_INPUT, "
                szSql &= "  BEGIN_TIME, BEGIN_OPT "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                       "'{5}', '{6}', '{7}', " &
                                       "'{8}', '{9}', '{10}', " &
                                       "'{11}', '{12}', " &
                                       "'{13}', '{14}', '{15}', '{16}', " &
                                       "'{17}', '{18}'",
                                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                      .Item("DB_EQUIP_RECIPE"), .Item("DB_WAFER_SUPPLY"), .Item("DB_GRADE"),
                                      .Item("DB_PASTE"), .Item("DB_PASTE_CONTNUM"), .Item("DB_PASTE_LOT"),
                                      .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"),
                                      .Item("DB_FRAME_MARK"), .Item("DB_CHIP_ARRANGE"), .Item("SELF_CHECK"), .Item("WAFER_INPUT"),
                                      dte, szBeginOpt,
                                      szMemo, szPlanqty)
                szSql &= ")"
                ' 蘇州対応 2017/04/24 T.Yutaro Upd End
                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                UpdateEquipMatDB = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If

            End With
        End If

        DBacs.CommitTransaction()
    End Function


    'Public Function UpdateEquipMatDB(ByVal szOldEquipID As String, ByVal szEquipID As String, _
    '                                 ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String, _
    '                                 ByVal szProcCD As String, ByVal dtEquipMat As DataTable, _
    '                                 ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, _
    '                                 ByVal szMemo As String, ByVal szPlanqty As String, ByVal dtHeader As DataTable) As Integer
    '    DBacs.BeginTransaction()

    '    Dim szSql As String = ""
    '    szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
    '    szSql &= "SET "
    '    'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
    '    'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
    '    szSql &= "  IS_DONE = TRUE "
    '    szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
    '    szSql &= "AND LOT_NO='" & szLotNo & "' "
    '    szSql &= "AND IS_CONDITION=FALSE "

    '    DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

    '    'ヘッダー情報を保存
    '    Dim dte As DateTime = SaveHeader(dtHeader, szLotNo, szEquipID, szBeginTM)

    '    If dte = DateTime.MinValue Then
    '        DBacs.RollbackTransaction()
    '        Return -10
    '    Else
    '        szBeginTM = dte
    '    End If

    '    Dim cnt As Integer

    '    '製造条件
    '    With dtEquipMat.Rows(1)

    '        szSql = ""
    '        szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
    '        szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
    '        szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
    '        szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
    '        szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
    '        szSql &= "  DB_SUBCHIP, "
    '        szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
    '        szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
    '        szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
    '        szSql &= "  DB_FRAME_MARK, DB_CHIP_ARRANGE, DB_DIE_SIZE, DB_CURE, "
    '        szSql &= "  BEGIN_TIME, BEGIN_OPT,  "
    '        szSql &= "  DB_MEMO, DB_PLAN_QTY  "
    '        szSql &= ") "
    '        szSql &= "VALUES ( "
    '        szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " & _
    '                               "'{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', " & _
    '                               "'{12}', '{13}', '{14}', " & _
    '                               "'{15}', '{16}', '{17}', " & _
    '                               "'{18}', " & _
    '                               "'{19}', '{20}', '{21}', '{22}', '{23}', " & _
    '                               "'{24}', '{25}', '{26}', '{27}', '{28}', " & _
    '                               "'{29}', '{30}', '{31}', '{32}', '{33}', " & _
    '                               "'{34}', '{35}', '{36}', '{37}', " & _
    '                               "'{38}', '{39}', " & _
    '                               "'{40}', '{41}'", _
    '                              szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
    '                              .Item("DB_GUM_COLLET"), .Item("DB_COLLET"), .Item("DB_POCKET"), .Item("DB_PIN"), .Item("DB_KOMA"), .Item("DB_STAGE"), .Item("DB_NOZZLE"), _
    '                              .Item("DB_PASTE"), .Item("DB_PASTE_LOT"), .Item("DB_PASTE_LT"), _
    '                              .Item("DB_PASTE2"), .Item("DB_PASTE_LOT2"), .Item("DB_PASTE_LT2"), _
    '                              .Item("DB_SUBCHIP"), _
    '                              .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"), .Item("DB_FRM_YL"), .Item("DB_FRAME_QTY"), .Item("DB_FRAME_LT"), _
    '                              .Item("DB_FRAME_NAME2"), .Item("DB_FRAME_LOT2"), .Item("DB_FRM_YL2"), .Item("DB_FRAME_QTY2"), .Item("DB_FRAME_LT2"), _
    '                              .Item("DB_FRAME_NAME3"), .Item("DB_FRAME_LOT3"), .Item("DB_FRM_YL3"), .Item("DB_FRAME_QTY3"), .Item("DB_FRAME_LT3"), _
    '                              .Item("DB_FRAME_MARK"), .Item("DB_CHIP_ARRANGE"), .Item("DB_DIE_SIZE"), .Item("DB_CURE"), _
    '                             dte, szBeginOpt, _
    '                              szMemo, szPlanqty)
    '        szSql &= ")"

    '        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
    '        UpdateEquipMatDB = cnt
    '        If cnt < 0 Then
    '            DBacs.RollbackTransaction()
    '            Exit Function
    '        End If
    '    End With

    '    With dtEquipMat.Rows(0)

    '        szSql = ""
    '        szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
    '        szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
    '        szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
    '        szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
    '        szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
    '        szSql &= "  DB_SUBCHIP, "
    '        szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
    '        szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
    '        szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
    '        szSql &= "  DB_FRAME_MARK, DB_CURE, "
    '        szSql &= "  BEGIN_TIME, BEGIN_OPT "
    '        szSql &= ") "
    '        szSql &= "VALUES ( "
    '        szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " & _
    '                               "'{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', " & _
    '                               "'{12}', '{13}', '{14}', " & _
    '                               "'{15}', '{16}', '{17}', " & _
    '                               "'{18}', " & _
    '                               "'{19}', '{20}', '{21}', '{22}', '{23}', " & _
    '                               "'{24}', '{25}', '{26}', '{27}', '{28}', " & _
    '                               "'{29}', '{30}', '{31}', '{32}', '{33}', " & _
    '                               "'{34}', '{35}', " & _
    '                               "'{36}', '{37}'", _
    '                              szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
    '                              .Item("DB_GUM_COLLET"), .Item("DB_COLLET"), .Item("DB_POCKET"), .Item("DB_PIN"), .Item("DB_KOMA"), .Item("DB_STAGE"), .Item("DB_NOZZLE"), _
    '                              .Item("DB_PASTE"), .Item("DB_PASTE_LOT"), .Item("DB_PASTE_LT"), _
    '                              .Item("DB_PASTE2"), .Item("DB_PASTE_LOT2"), .Item("DB_PASTE_LT2"), _
    '                              .Item("DB_SUBCHIP"), _
    '                              .Item("DB_FRAME_NAME"), .Item("DB_FRAME_LOT"), .Item("DB_FRM_YL"), .Item("DB_FRAME_QTY"), .Item("DB_FRAME_LT"), _
    '                              .Item("DB_FRAME_NAME2"), .Item("DB_FRAME_LOT2"), .Item("DB_FRM_YL2"), .Item("DB_FRAME_QTY2"), .Item("DB_FRAME_LT2"), _
    '                              .Item("DB_FRAME_NAME3"), .Item("DB_FRAME_LOT3"), .Item("DB_FRM_YL3"), .Item("DB_FRAME_QTY3"), .Item("DB_FRAME_LT3"), _
    '                              .Item("DB_FRAME_MARK"), .Item("DB_CURE"), _
    '                             dte, szBeginOpt)
    '        szSql &= ")"

    '        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
    '        UpdateEquipMatDB = cnt
    '        If cnt < 0 Then
    '            DBacs.RollbackTransaction()
    '            Exit Function
    '        End If
    '    End With

    '    DBacs.CommitTransaction()
    'End Function

    ' 蘇州対応 2017/04/14 T.Yutaro Add Start
    Public Function SaveEquipMatDB(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTable As String, ByVal htFinish As Hashtable) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  DB_PASTE2 ='" & htFinish("DB_PASTE2") & "', "
        szSql &= "  DB_PASTE_CONTNUM2 ='" & htFinish("DB_PASTE_CONTNUM2") & "', "
        szSql &= "  DB_PASTE_LOT2 ='" & htFinish("DB_PASTE_LOT2") & "', "
        szSql &= "  DB_FRAME_NAME2 ='" & htFinish("DB_FRAME_NAME2") & "', "
        szSql &= "  DB_FRAME_LOT2 ='" & htFinish("DB_FRAME_LOT2") & "', "
        szSql &= "  DB_FRAME_NAME3 ='" & htFinish("DB_FRAME_NAME3") & "', "
        szSql &= "  DB_FRAME_LOT3 ='" & htFinish("DB_FRAME_LOT3") & "', "
        szSql &= "  SELF_CHECK_QTY ='" & htFinish("SELF_CHECK_QTY") & "', "
        szSql &= "  CASE_NO ='" & htFinish("CASE_NO") & "', "
        szSql &= "  RACK_NO1 ='" & htFinish("RACK_NO1") & "', "
        szSql &= "  RACK_NO2 ='" & htFinish("RACK_NO2") & "', "
        szSql &= "  RACK_NO3 ='" & htFinish("RACK_NO3") & "', "
        szSql &= "  RACK_NO4 ='" & htFinish("RACK_NO4") & "', "
        szSql &= "  WAFER_COMPLETE ='" & htFinish("WAFER_COMPLETE") & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function SaveEquipMatPlasmaWB(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTable As String, ByVal htFinish As Hashtable) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  CASE_NO ='" & htFinish("CASE_NO") & "', "
        szSql &= "  RACK_NO1 ='" & htFinish("RACK_NO1") & "', "
        szSql &= "  RACK_NO2 ='" & htFinish("RACK_NO2") & "', "
        szSql &= "  RACK_NO3 ='" & htFinish("RACK_NO3") & "', "
        szSql &= "  RACK_NO4 ='" & htFinish("RACK_NO4") & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetPreWaferComplete(ByVal szLotNo As String, ByVal preTable As String) As String
        Dim szSql As String = ""
        szSql &= "SELECT WAFER_COMPLETE "
        szSql &= "FROM MAT." & preTable & " "
        szSql &= "WHERE LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "
        szSql &= "ORDER BY SYS_CMD_ID DESC "
        szSql &= "LIMIT 1 "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szLotNo)
        GetPreWaferComplete = String.Empty
        If IsNothing(dt) Then
            GetPreWaferComplete = String.Empty
        Else
            SolveNull(dt)
            For Each dr As DataRow In dt.Rows
                GetPreWaferComplete = dr("WAFER_COMPLETE")
            Next
        End If
    End Function

    Public Function GetPreCaseAndRack(ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus, ByVal preTable As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT CASE_NO, RACK_NO1, RACK_NO2, RACK_NO3, RACK_NO4 "
        szSql &= "FROM MAT." & preTable & " "
        szSql &= "WHERE LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "
        szSql &= "ORDER BY SYS_CMD_ID DESC "
        szSql &= "LIMIT 1 "
        Try
            Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
            If IsNothing(dt) Then
                GetPreCaseAndRack = New DataTable
            Else
                SolveNull(dt)
                GetPreCaseAndRack = dt
            End If
        Catch ex As Exception
            GetPreCaseAndRack = New DataTable
        End Try
    End Function
    ' 蘇州対応 2017/04/14 T.Yutaro Add End

    Public Function SaveDbFrame(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                ByVal szFrm() As String, ByVal szFrm2() As String, ByVal szFrm3() As String,
                                Optional ByVal dteBeginTM As DateTime = Nothing) As Integer

        DBacs.BeginTransaction()
        Dim cnt As Integer

        Dim szSql As String = ""

        szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
        szSql &= "SET "
        If Not String.IsNullOrEmpty(szLotNo) Then
            szSql &= "LOT_NO = '" & szLotNo & "', "
        End If
        szSql &= "  DB_FRAME_NAME ='" & szFrm(0) & "', "
        szSql &= "  DB_FRAME_LOT ='" & szFrm(1) & "', "
        szSql &= "  DB_FRM_YL ='" & szFrm(2) & "', "
        szSql &= "  DB_FRAME_QTY ='" & szFrm(3) & "', "
        szSql &= "  DB_FRAME_LT ='" & szFrm(4) & "', "
        szSql &= "  DB_FRAME_NAME2 ='" & szFrm2(0) & "', "
        szSql &= "  DB_FRAME_LOT2 ='" & szFrm2(1) & "', "
        szSql &= "  DB_FRM_YL2 ='" & szFrm2(2) & "', "
        szSql &= "  DB_FRAME_QTY2 ='" & szFrm2(3) & "', "
        szSql &= "  DB_FRAME_LT2 ='" & szFrm2(4) & "', "
        szSql &= "  DB_FRAME_NAME3 ='" & szFrm3(0) & "', "
        szSql &= "  DB_FRAME_LOT3 ='" & szFrm3(1) & "', "
        szSql &= "  DB_FRM_YL3 ='" & szFrm3(2) & "', "
        szSql &= "  DB_FRAME_QTY3 ='" & szFrm3(3) & "', "
        szSql &= "  DB_FRAME_LT3 ='" & szFrm3(4) & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO IN ('" & szLotNo & "', '') "

        If IsNothing(dteBeginTM) OrElse dteBeginTM = DateTime.MinValue Then
            szSql &= "AND BEGIN_OPT = '' "
            'Else
            '    szSql &= "AND BEGIN_TIME = ? "
        End If
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "
        cnt = DBacs.ExecuteUpdateSql(szSql, -1, dteBeginTM)
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Return cnt
        ElseIf cnt = 0 Then
            If Not IsNothing(dteBeginTM) AndAlso Not dteBeginTM = DateTime.MinValue Then
                DBacs.RollbackTransaction()
                Return -10
            End If
            '古い記録のクリア
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
            szSql &= "SET "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO IN ('" & szLotNo & "', '') "
            szSql &= "AND IS_CONDITION=FALSE "

            cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            End If


            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
            szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
            szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
            szSql &= "  DB_SUBCHIP, "
            szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
            szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
            szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
            szSql &= "  DB_FRAME_MARK, DB_CURE, "
            szSql &= "  BEGIN_OPT "
            szSql &= ") "
            'szSql &= "VALUES ( "
            szSql &= "SELECT SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, '" & szLotNo & "', '', "
            szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
            szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
            szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
            szSql &= "  DB_SUBCHIP, "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}', '{12}', '{13}', '{14}', ",
                                  szFrm(0), szFrm(1), szFrm(2), szFrm(3), szFrm(4),
                                  szFrm2(0), szFrm2(1), szFrm2(2), szFrm2(3), szFrm2(4),
                                  szFrm3(0), szFrm3(1), szFrm3(2), szFrm3(3), szFrm3(4))

            szSql &= "  DB_FRAME_MARK, DB_CURE, "
            szSql &= "  ''"
            szSql &= "FROM MAT.L_EQUIP_MAT_DB "
            szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
            szSql &= "AND IS_CONDITION=FALSE "
            szSql &= "ORDER BY SYS_CMD_ID DESC "
            szSql &= "LIMIT 1 "
            'szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            ElseIf cnt = 0 Then
                szSql = ""
                szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
                szSql &= "  EQUIP_ID, LOT_NO, "
                szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
                szSql &= "  DB_FRAME_NAME2,DB_FRAME_LOT2,DB_FRM_YL2,DB_FRAME_QTY2,DB_FRAME_LT2, "
                szSql &= "  DB_FRAME_NAME3,DB_FRAME_LOT3,DB_FRM_YL3,DB_FRAME_QTY3,DB_FRAME_LT3 "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', " &
                                       "'{2}', '{3}', '{4}', '{5}', '{6}', " &
                                       "'{7}', '{8}', '{9}', '{10}', '{11}', " &
                                       "'{12}', '{13}', '{14}', '{15}', '{16}'",
                                      szEquipID, szLotNo,
                                      szFrm(0), szFrm(1), szFrm(2), szFrm(3), szFrm(4),
                                      szFrm2(0), szFrm2(1), szFrm2(2), szFrm2(3), szFrm2(4),
                                      szFrm3(0), szFrm3(1), szFrm3(2), szFrm3(3), szFrm3(4))
                szSql &= ")"
                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Return cnt
                Else
                    SaveDbFrame = cnt
                End If
            Else
                SaveDbFrame = cnt
            End If
        Else
            SaveDbFrame = cnt
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function SaveDbPaste(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal szPaste() As String, ByVal szPaste2() As String,
                                Optional ByVal dteBeginTM As DateTime = Nothing) As Integer

        DBacs.BeginTransaction()
        Dim cnt As Integer

        Dim szSql As String = ""
        'szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
        'szSql &= "SET "
        'szSql &= "  DB_PASTE ='" & szPaste(0) & "', "
        'szSql &= "  DB_PASTE_LOT ='" & szPaste(1) & "', "
        'szSql &= "  DB_PASTE_LT ='" & szPaste(2) & "', "
        'szSql &= "  DB_PASTE2 ='" & szPaste2(0) & "', "
        'szSql &= "  DB_PASTE_LOT2 ='" & szPaste2(1) & "', "
        'szSql &= "  DB_PASTE_LT2 ='" & szPaste2(2) & "' "
        'szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        'szSql &= "AND LOT_NO='" & szLotNo & "' "
        'szSql &= "AND IS_DONE = FALSE "
        'szSql &= "AND IS_CONDITION=FALSE "

        szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
        szSql &= "SET "
        If Not String.IsNullOrEmpty(szLotNo) Then
            szSql &= "LOT_NO = '" & szLotNo & "', "
        End If
        szSql &= "  DB_PASTE ='" & szPaste(0) & "', "
        szSql &= "  DB_PASTE_LOT ='" & szPaste(1) & "', "
        szSql &= "  DB_PASTE_LT ='" & szPaste(2) & "', "
        szSql &= "  DB_PASTE2 ='" & szPaste2(0) & "', "
        szSql &= "  DB_PASTE_LOT2 ='" & szPaste2(1) & "', "
        szSql &= "  DB_PASTE_LT2 ='" & szPaste2(2) & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO IN ('" & szLotNo & "', '') "

        If IsNothing(dteBeginTM) OrElse dteBeginTM = DateTime.MinValue Then
            szSql &= "AND BEGIN_OPT = '' "
            'Else
            '    szSql &= "AND BEGIN_TIME = ? "
        End If
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "
        cnt = DBacs.ExecuteUpdateSql(szSql, -1, dteBeginTM)
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Return cnt
        ElseIf cnt = 0 Then
            If Not IsNothing(dteBeginTM) AndAlso Not dteBeginTM = DateTime.MinValue Then
                DBacs.RollbackTransaction()
                Return -10
            End If
            '古い記録のクリア
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_DB "
            szSql &= "SET "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO IN ('" & szLotNo & "', '') "
            szSql &= "AND IS_CONDITION=FALSE "

            cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            End If

            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
            szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
            szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2, "
            szSql &= "  DB_SUBCHIP, "
            szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
            szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
            szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
            szSql &= "  DB_FRAME_MARK, DB_CURE, "
            szSql &= "  BEGIN_OPT "
            szSql &= ") "
            'szSql &= "VALUES ( "
            szSql &= "SELECT SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, '" & szLotNo & "', '', "
            szSql &= "  DB_GUM_COLLET, DB_COLLET, DB_POCKET, DB_PIN, DB_KOMA, DB_STAGE, DB_NOZZLE, "
            szSql &= String.Format("'{0}', '{1}', '{2}', " &
                                   "'{3}', '{4}', '{5}', ",
                                  szPaste(0), szPaste(1), szPaste(2),
                                  szPaste2(0), szPaste2(1), szPaste2(2))

            szSql &= "  DB_SUBCHIP, "
            szSql &= "  DB_FRAME_NAME, DB_FRAME_LOT, DB_FRM_YL, DB_FRAME_QTY, DB_FRAME_LT, "
            szSql &= "  DB_FRAME_NAME2, DB_FRAME_LOT2, DB_FRM_YL2, DB_FRAME_QTY2, DB_FRAME_LT2, "
            szSql &= "  DB_FRAME_NAME3, DB_FRAME_LOT3, DB_FRM_YL3, DB_FRAME_QTY3, DB_FRAME_LT3, "
            szSql &= "  DB_FRAME_MARK, DB_CURE, "
            szSql &= "  '' "
            szSql &= "FROM MAT.L_EQUIP_MAT_DB "
            szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
            szSql &= "AND IS_CONDITION=FALSE "
            szSql &= "ORDER BY SYS_CMD_ID DESC "
            szSql &= "LIMIT 1 "
            'szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            ElseIf cnt = 0 Then
                szSql = ""
                szSql &= "INSERT INTO MAT.L_EQUIP_MAT_DB( "
                szSql &= "  EQUIP_ID, LOT_NO, "
                szSql &= "  DB_PASTE, DB_PASTE_LOT, DB_PASTE_LT, "
                szSql &= "  DB_PASTE2, DB_PASTE_LOT2, DB_PASTE_LT2 "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', " &
                                       "'{2}', '{3}', '{4}', " &
                                       "'{5}', '{6}', '{7}' ",
                                  szEquipID, szLotNo,
                                  szPaste(0), szPaste(1), szPaste(2),
                                  szPaste2(0), szPaste2(1), szPaste2(2))
                szSql &= ")"
                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Return cnt
                Else
                    SaveDbPaste = cnt
                End If
            Else
                SaveDbPaste = cnt
            End If
        Else
            SaveDbPaste = cnt
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatDbAfc(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  SV2.DBAFC_RACK1, SV2.DBAFC_RACK2, SV2.DBAFC_RACK3, SV2.DBAFC_RACK4, "
        szSql &= "  SV2.DBAFC_RACK5, SV2.DBAFC_RACK6, SV2.DBAFC_RACK7, SV2.DBAFC_RACK8, "
        szSql &= "  SV2.DBAFC_RACK9, SV2.DBAFC_RACK10 "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_DBAFC")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatDbAfc = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatDbAfc = dt
        End If
    End Function

    Public Function UpdateEquipMatDbAfc(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_DBAFC "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_DBAFC ( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  DBAFC_RACK1, DBAFC_RACK2, "
            szSql &= "  DBAFC_RACK3, DBAFC_RACK4, "
            szSql &= "  DBAFC_RACK5, DBAFC_RACK6, "
            szSql &= "  DBAFC_RACK7, DBAFC_RACK8, "
            szSql &= "  DBAFC_RACK9, DBAFC_RACK10, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}', '{12}', '{13}', '{14}', " &
                                   "'{15}', '{16}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("DBAFC_RACK1"), .Item("DBAFC_RACK2"), .Item("DBAFC_RACK3"), .Item("DBAFC_RACK4"), .Item("DBAFC_RACK5"),
                                  .Item("DBAFC_RACK6"), .Item("DBAFC_RACK7"), .Item("DBAFC_RACK8"), .Item("DBAFC_RACK9"), .Item("DBAFC_RACK10"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatDbAfc = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatPlasmaWB(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  SV2.PLASMA_WB_COND, SV2.PLASMA_WB_THICK, "
        ' 蘇州対応 2017/04/14 T.Yutaro Add Start
        szSql &= "  SV2.CASE_NO, SV2.RACK_NO1, SV2.RACK_NO2, SV2.RACK_NO3, SV2.RACK_NO4, "
        ' 蘇州対応 2017/04/14 T.Yutaro Add End
        szSql &= "  SV2.PLASMA_WB_MEMO "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_PLASMA_WB")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPlasmaWB = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPlasmaWB = dt
        End If
    End Function

    ''' <summary>
    ''' WB前プラズマ治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatPlasmaWB(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal szMemo As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PLASMA_WB "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            ' 蘇州対応 2017/04/26 T.Yutaro Upd Start
            'szSql = ""
            'szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_WB( "
            'szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            'szSql &= "  PLASMA_WB_COND, PLASMA_WB_THICK, "
            'szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            'szSql &= "  PLASMA_WB_MEMO "
            'szSql &= ") "
            'szSql &= "VALUES ( "
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " & _
            '                       "'{5}', '{6}', " & _
            '                       "'{7}', '{8}', " & _
            '                       "'{9}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("PLASMA_WB_COND"), .Item("PLASMA_WB_THICK"), _
            '                     dte, szBeginOpt, _
            '                      szMemo)
            'szSql &= ")"
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_WB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  PLASMA_WB_COND, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            szSql &= "  PLASMA_WB_MEMO "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}',  " &
                                   "'{6}', '{7}', " &
                                   "'{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PLASMA_WB_COND"),
                                 dte, szBeginOpt,
                                  szMemo)
            szSql &= ")"
            ' 蘇州対応 2017/04/26 T.Yutaro Upd End
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPlasmaWB = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = ""
            ' 蘇州対応 2017/04/26 T.Yutaro Upd Start
            'szSql &= "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_WB( "
            'szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            'szSql &= "  PLASMA_WB_COND, PLASMA_WB_THICK, "
            'szSql &= "  BEGIN_TIME, BEGIN_OPT "
            'szSql &= ") "
            'szSql &= "VALUES ( "
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " & _
            '                       "'{5}', '{6}', " & _
            '                       "'{7}', '{8}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("PLASMA_WB_COND"), .Item("PLASMA_WB_THICK"), _
            '                     dte, szBeginOpt)
            'szSql &= ")"
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_WB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  PLASMA_WB_COND, "
            szSql &= "  CASE_NO, RACK_NO1, RACK_NO2, RACK_NO3, RACK_NO4, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}', '{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PLASMA_WB_COND"),
                                  .Item("CASE_NO"), .Item("RACK_NO1"), .Item("RACK_NO2"), .Item("RACK_NO3"), .Item("RACK_NO4"),
                                 dte, szBeginOpt)
            szSql &= ")"
            ' 蘇州対応 2017/04/26 T.Yutaro Upd End
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPlasmaWB = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatWB(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  MAT.WB_FRAME_ID, MAT.WB_PIN, MAT.WB_KOMA, MAT.WB_WIRE, MAT.WB_WIRE_LOT, "
        szSql &= "  MAT.WB_TEMP, MAT.WB_CAPILLARY, MAT.WB_CAPI_LOT, MAT.WB_THICK, MAT.WB_LIMIT_TIME, "
        szSql &= "  SV2.WB_PUSH_TIME, SV2.WB_PULL_TIME, SV2.WB_MEMO, "
        szSql &= "  TO_CHAR(SAV.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS LAST_TIME, MAT.WB_CASE_INPUT "
        szSql &= SqlCondLot(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_WB", "L_EQUIP_MAT_PLASMA_WB")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatWB = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatWB = dt
        End If
    End Function

    ''' <summary>
    ''' WB治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatWB(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                     ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                     ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                     ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                     ByVal szMemo As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_WB "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""

            szSql = "INSERT INTO MAT.L_EQUIP_MAT_WB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  WB_FRAME_ID, WB_PIN, WB_KOMA, WB_WIRE, WB_WIRE_LOT, "
            szSql &= "  WB_TEMP, WB_CAPILLARY, WB_CAPI_LOT, WB_THICK, WB_LIMIT_TIME, "
            szSql &= "  WB_PUSH_TIME, WB_PULL_TIME, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            szSql &= "  WB_MEMO, WB_CASE_INPUT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}', '{12}', '{13}', '{14}', " &
                                   "'{15}', '{16}', " &
                                   "'{17}', '{18}', " &
                                   "'{19}', '{20}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("WB_FRAME_ID"), .Item("WB_PIN"), .Item("WB_KOMA"),
                                  .Item("WB_WIRE"), .Item("WB_WIRE_LOT"), .Item("WB_TEMP"),
                                  .Item("WB_CAPILLARY"), .Item("WB_CAPI_LOT"), .Item("WB_THICK"), .Item("WB_LIMIT_TIME"),
                                  .Item("WB_PUSH_TIME"), .Item("WB_PULL_TIME"),
                                 dte, szBeginOpt,
                                  szMemo, .Item("WB_CASE_INPUT"))
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatWB = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)

            szSql = "INSERT INTO MAT.L_EQUIP_MAT_WB( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  WB_FRAME_ID, WB_PIN, WB_KOMA, WB_WIRE, WB_WIRE_LOT, "
            szSql &= "  WB_TEMP, WB_CAPILLARY, WB_CAPI_LOT, WB_THICK, WB_LIMIT_TIME, "
            szSql &= "  WB_PUSH_TIME, WB_PULL_TIME, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, WB_CASE_INPUT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}', '{12}', '{13}', '{14}', " &
                                   "'{15}', '{16}', " &
                                   "'{17}', '{18}', '{19}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("WB_FRAME_ID"), .Item("WB_PIN"), .Item("WB_KOMA"),
                                  .Item("WB_WIRE"), .Item("WB_WIRE_LOT"), .Item("WB_TEMP"),
                                  .Item("WB_CAPILLARY"), .Item("WB_CAPI_LOT"), .Item("WB_THICK"), .Item("WB_LIMIT_TIME"),
                                  .Item("WB_PUSH_TIME"), .Item("WB_PULL_TIME"),
                                 dte, szBeginOpt, .Item("WB_CASE_INPUT"))
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatWB = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveWbWire(ByVal szLotNo As String, ByVal szEquipID As String, ByVal szWire As String) As Integer
        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_WB "
        szSql &= "SET "
        szSql &= "  WB_WIRE  ='" & szWire & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatInsp(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, sv2.CHECK_QTY, "
        ' 蘇州対応 2017/04/14 T.Yutaro Upd Start
        'szSql &= "  SV2.ASM_V_COND, SV2.ASM_V_MEMO "
        'szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_INSP")
        szSql &= "  SV2.ASM_V_COND, SV2.ASM_V_MEMO, SV2.ASM_V_CHIP_TYPE "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_INSP")
        ' 蘇州対応 2017/04/14 T.Yutaro Upd End


        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatInsp = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatInsp = dt
        End If
    End Function

    ''' <summary>
    ''' 組立外観治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatInsp(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal szMemo As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_INSP "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_INSP( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            ' 蘇州対応 2017/04/14 T.Yutaro Upd Start
            'szSql &= "  ASM_V_COND, ASM_V_MEMO, "
            szSql &= "  ASM_V_COND, ASM_V_MEMO, ASM_V_CHIP_TYPE, "
            ' 蘇州対応 2017/04/14 T.Yutaro Upd End
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            ' 蘇州対応 2017/04/14 T.Yutaro Upd Start
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " & _
            '                       "'{5}', '{6}', " & _
            '                       "'{7}', '{8}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("ASM_V_COND"), szMemo, _
            '                     dte, szBeginOpt)
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("ASM_V_COND"), szMemo, .Item("ASM_V_CHIP_TYPE"),
                                 dte, szBeginOpt)
            ' 蘇州対応 2017/04/14 T.Yutaro Upd End
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatInsp = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_INSP( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            ' 蘇州対応 2017/04/14 T.Yutaro Upd Start
            'szSql &= "  ASM_V_COND, "
            szSql &= "  ASM_V_COND, ASM_V_CHIP_TYPE, "
            ' 蘇州対応 2017/04/14 T.Yutaro Upd End
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            ' 蘇州対応 2017/04/14 T.Yutaro Upd Start
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " & _
            '                       "'{5}', " & _
            '                       "'{6}', '{7}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("ASM_V_COND"), _
            '                     dte, szBeginOpt)
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("ASM_V_COND"), .Item("ASM_V_CHIP_TYPE"),
                                 dte, szBeginOpt)
            ' 蘇州対応 2017/04/14 T.Yutaro Upd End
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatInsp = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    ' 蘇州対応 2017/04/14 T.Yutaro Add Start
    Public Function SaveEquipMatInsp(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTable As String, ByVal htFinish As Hashtable) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  CASE_NO ='" & htFinish("CASE_NO") & "', "
        szSql &= "  RACK_NO1 ='" & htFinish("RACK_NO1") & "', "
        szSql &= "  RACK_NO2 ='" & htFinish("RACK_NO2") & "', "
        szSql &= "  RACK_NO3 ='" & htFinish("RACK_NO3") & "', "
        szSql &= "  RACK_NO4 ='" & htFinish("RACK_NO4") & "', "
        szSql &= "  CHECK_QTY ='" & htFinish("CHECK_QTY") & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function
    ' 蘇州対応 2017/04/14 T.Yutaro Add End

    Public Function GetEquipMatPlasmaMD(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  SV2.PLASMA_MD_COND, SV2.PLASMA_MD_THICK, "
        ' 蘇州対応 2017/04/26 T.Yutaro Add Start
        szSql &= "  SV2.CASE_NO, SV2.RACK_NO1, SV2.RACK_NO2, SV2.RACK_NO3, SV2.RACK_NO4, "
        ' 蘇州対応 2017/04/26 T.Yutaro Add End
        szSql &= "  SV2.PLASMA_MD_MEMO1, SV2.PLASMA_MD_MEMO2 "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_PLASMA_MD")


        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPlasmaMD = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPlasmaMD = dt
        End If
    End Function

    ''' <summary>
    ''' MD前プラズマ治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatPlasmaMD(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PLASMA_MD "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""
            ' 蘇州対応 2017/04/26 T.Yutaro Upd Start
            'szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_MD( "
            'szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            'szSql &= "  PLASMA_MD_COND, PLASMA_MD_THICK, "
            'szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            'szSql &= "  PLASMA_MD_MEMO1, PLASMA_MD_MEMO2 "
            'szSql &= ") "
            'szSql &= "VALUES ( "
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " & _
            '                       "'{5}', '{6}', " & _
            '                       "'{7}', '{8}', " & _
            '                       "'{9}', '{10}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("PLASMA_MD_COND"), .Item("PLASMA_MD_THICK"), _
            '                     dte, szBeginOpt, _
            '                      szMemo1, szMemo2)
            'szSql &= ")"
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_MD( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  PLASMA_MD_COND, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            szSql &= "  PLASMA_MD_MEMO1, PLASMA_MD_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{7}', '{8}', " &
                                   "'{9}', '{10}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PLASMA_MD_COND"),
                                 dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"
            ' 蘇州対応 2017/04/26 T.Yutaro Upd End
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPlasmaMD = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            ' 蘇州対応 2017/04/26 T.Yutaro Upd Start
            'szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_MD( "
            'szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            'szSql &= "  PLASMA_MD_COND, PLASMA_MD_THICK, "
            'szSql &= "  BEGIN_TIME, BEGIN_OPT "
            'szSql &= ") "
            'szSql &= "VALUES ( "
            'szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " & _
            '                       "'{5}', '{6}', " & _
            '                       "'{7}', '{8}'", _
            '                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
            '                      .Item("PLASMA_MD_COND"), .Item("PLASMA_MD_THICK"), _
            '                     dte, szBeginOpt)
            'szSql &= ")"
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLASMA_MD( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  PLASMA_MD_COND, "
            szSql &= "  CASE_NO, RACK_NO1, RACK_NO2, RACK_NO3, RACK_NO4, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}', '{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PLASMA_MD_COND"), .Item("PLASMA_MD_THICK"),
                                 dte, szBeginOpt)
            szSql &= ")"
            ' 蘇州対応 2017/04/26 T.Yutaro Upd End
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPlasmaMD = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatMold(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= " SV2.MOLD_LIMIT_TIME, SV2.MOLD_TOOL, SV2.MOLD_FRAME, SV2.MOLD_THICK, "
        szSql &= " MAT.MOLD_RESIN, MAT.MOLD_RESIN_LOT, MAT.MOLD_MAKER_LOT, MAT.MOLD_RESIN_LT, "
        szSql &= " MAT.MOLD_RESIN2, MAT.MOLD_RESIN_LOT2, MAT.MOLD_MAKER_LOT2, MAT.MOLD_RESIN_LT2, "
        szSql &= " MAT.MOLD_RESIN3, MAT.MOLD_RESIN_LOT3, MAT.MOLD_MAKER_LOT3, MAT.MOLD_RESIN_LT3, "
        szSql &= " SV2.MOLD_RACK , SV2.MOLD_FRM_ID, "
        szSql &= " SV2.MOLD_PUSH_TIME , SV2.MOLD_PULL_TIME , "
        szSql &= " TO_CHAR(SAV.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS LAST_TIME "
        szSql &= SqlCondLot(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_MOLD", "L_EQUIP_MAT_PLASMA_MD")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatMold = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatMold = dt
        End If
    End Function

    ''' <summary>
    ''' Mold治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatMold(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                       ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MOLD "
        szSql &= "SET "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MOLD( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  MOLD_LIMIT_TIME, MOLD_TOOL, MOLD_FRAME, MOLD_THICK, "
            szSql &= "  MOLD_RESIN, MOLD_RESIN_LOT, MOLD_MAKER_LOT, MOLD_RESIN_LT, "
            szSql &= "  MOLD_RESIN2, MOLD_RESIN_LOT2, MOLD_MAKER_LOT2, MOLD_RESIN_LT2, "
            szSql &= "  MOLD_RESIN3, MOLD_RESIN_LOT3, MOLD_MAKER_LOT3, MOLD_RESIN_LT3, "
            szSql &= "  MOLD_RACK, "
            szSql &= "  MOLD_PUSH_TIME, MOLD_PULL_TIME, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            szSql &= "  MOLD_MEMO1, MOLD_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', " &
                                   "'{9}', '{10}', '{11}', '{12}', " &
                                   "'{13}', '{14}', '{15}', '{16}', " &
                                   "'{17}', '{18}', '{19}', '{20}', " &
                                   "'{21}', " &
                                   "'{22}', '{23}', " &
                                   "'{24}', '{25}', " &
                                   "'{26}', '{27}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("MOLD_LIMIT_TIME"), .Item("MOLD_TOOL"), .Item("MOLD_FRAME"), .Item("MOLD_THICK"),
                                  .Item("MOLD_RESIN"), .Item("MOLD_RESIN_LOT"), .Item("MOLD_MAKER_LOT"), .Item("MOLD_RESIN_LT"),
                                  .Item("MOLD_RESIN2"), .Item("MOLD_RESIN_LOT2"), .Item("MOLD_MAKER_LOT2"), .Item("MOLD_RESIN_LT2"),
                                  .Item("MOLD_RESIN3"), .Item("MOLD_RESIN_LOT3"), .Item("MOLD_MAKER_LOT3"), .Item("MOLD_RESIN_LT3"),
                                  .Item("MOLD_RACK"),
                                  .Item("MOLD_PUSH_TIME"), .Item("MOLD_PULL_TIME"),
                                 dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMold = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If


        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MOLD( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  MOLD_LIMIT_TIME, MOLD_TOOL, MOLD_FRAME, MOLD_THICK, "
            szSql &= "  MOLD_RESIN, MOLD_RESIN_LOT, MOLD_MAKER_LOT, MOLD_RESIN_LT, "
            szSql &= "  MOLD_RESIN2, MOLD_RESIN_LOT2, MOLD_MAKER_LOT2, MOLD_RESIN_LT2, "
            szSql &= "  MOLD_RESIN3, MOLD_RESIN_LOT3, MOLD_MAKER_LOT3, MOLD_RESIN_LT3, "
            szSql &= "  MOLD_RACK, MOLD_FRM_ID, "
            szSql &= "  MOLD_PUSH_TIME, MOLD_PULL_TIME, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', '{8}', " &
                                   "'{9}', '{10}', '{11}', '{12}', " &
                                   "'{13}', '{14}', '{15}', '{16}', " &
                                   "'{17}', '{18}', '{19}', '{20}', " &
                                   "'{21}', '{22}', " &
                                   "'{23}', '{24}', " &
                                   "'{25}', '{26}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("MOLD_LIMIT_TIME"), .Item("MOLD_TOOL"), .Item("MOLD_FRAME"), .Item("MOLD_THICK"),
                                  .Item("MOLD_RESIN"), .Item("MOLD_RESIN_LOT"), .Item("MOLD_MAKER_LOT"), .Item("MOLD_RESIN_LT"),
                                  .Item("MOLD_RESIN2"), .Item("MOLD_RESIN_LOT2"), .Item("MOLD_MAKER_LOT2"), .Item("MOLD_RESIN_LT2"),
                                  .Item("MOLD_RESIN3"), .Item("MOLD_RESIN_LOT3"), .Item("MOLD_MAKER_LOT3"), .Item("MOLD_RESIN_LT3"),
                                  .Item("MOLD_RACK"), .Item("MOLD_FRM_ID"),
                                  .Item("MOLD_PUSH_TIME"), .Item("MOLD_PULL_TIME"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMold = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If


        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveMoldResinRack(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szResin() As String, ByVal szRackID As String, ByVal szFrameID As String) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MOLD "
        szSql &= "SET "
        szSql &= "  MOLD_FRM_ID  ='" & szFrameID & "', "
        szSql &= "  MOLD_RESIN ='" & szResin(0) & "', "
        szSql &= "  MOLD_RESIN_LOT ='" & szResin(1) & "', "
        szSql &= "  MOLD_MAKER_LOT ='" & szResin(2) & "', "
        szSql &= "  MOLD_RESIN_LT ='" & szResin(3) & "', "
        szSql &= "  MOLD_RESIN2 ='', "
        szSql &= "  MOLD_RESIN_LOT2 ='', "
        szSql &= "  MOLD_MAKER_LOT2 ='', "
        szSql &= "  MOLD_RESIN_LT2 ='', "
        szSql &= "  MOLD_RESIN3 ='', "
        szSql &= "  MOLD_RESIN_LOT3 ='', "
        szSql &= "  MOLD_MAKER_LOT3 ='', "
        szSql &= "  MOLD_RESIN_LT3 ='', "
        szSql &= "  MOLD_RACK ='" & szRackID & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function SaveMoldFrmID(ByVal szLotNo As String, ByVal szEquipID As String, ByVal szRackID As String, ByVal szFrameID As String) As Integer
        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MOLD "
        szSql &= "SET "
        szSql &= "  MOLD_RACK ='" & szRackID & "', "
        szSql &= "  MOLD_FRM_ID  ='" & szFrameID & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatBM(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.CHG_BALL, SV2.CHG_FRAME, SV2.SELF_CHECK, "
        szSql &= " MAT.BM_BALL1, MAT.BM_BALL2, MAT.BM_LIMIT_TIME, "
        szSql &= " SV2.BM_PUSH_TIME, SV2.BM_PULL_TIME, "
        szSql &= " TO_CHAR(SAV.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS LAST_TIME "
        szSql &= SqlCondLot(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_BALL", "L_EQUIP_MAT_MOLD_AFC")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatBM = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatBM = dt
        End If
    End Function

    ''' <summary>
    ''' BM治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatBM(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                     ByVal szLotNo As String, ByVal szSysEquipID As String,
                                     ByVal szEquipNo As String, ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                     ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                     ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_BALL "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_BALL( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  BM_BALL1, BM_BALL2, BM_LIMIT_TIME,"
            szSql &= "  BM_PUSH_TIME, BM_PULL_TIME, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', " &
                                   "'{10}', '{11}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BM_BALL1"), .Item("BM_BALL2"), .Item("BM_LIMIT_TIME"),
                                  .Item("BM_PUSH_TIME"), .Item("BM_PULL_TIME"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBM = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_BALL( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  BM_BALL1, BM_BALL2, BM_LIMIT_TIME,"
            szSql &= "  BM_PUSH_TIME, BM_PULL_TIME, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', " &
                                   "'{10}', '{11}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BM_BALL1"), .Item("BM_BALL2"), .Item("BM_LIMIT_TIME"),
                                  .Item("BM_PUSH_TIME"), .Item("BM_PULL_TIME"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBM = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    'Public Function SaveMatBM(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String, ByVal szProcCD As String, ByVal dtEquipMat As DataTable, Byref szBeginTM As String, ByVal szBeginOpt As String) As Integer
    '    With dtEquipMat.Rows(0)
    '        Dim szSql As String = ""
    '        szSql = "INSERT INTO MAT.L_EQUIP_MAT_BALL( "
    '        szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
    '        szSql &= "  BM_BALL1, BM_BALL2, BM_LIMIT_TIME,"
    '        szSql &= "  BM_PUSH_TIME, BM_PULL_TIME, "
    '        szSql &= "  BEGIN_TIME, BEGIN_OPT "
    '        szSql &= ") "
    '        szSql &= "VALUES ( "
    '        szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " & _
    '                               "'{5}', '{6}', '{7}', " & _
    '                               "'{8}', '{9}', " & _
    '                               "'{10}', '{11}'", _
    '                              szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
    '                              .Item("BM_BALL1"), .Item("BM_BALL2"), .Item("BM_LIMIT_TIME"), _
    '                              .Item("BM_PUSH_TIME"), .Item("BM_PULL_TIME"), _
    '                             dte, szBeginOpt)
    '        szSql &= ")"

    '        Dim cnt As Integer = DBacs.ExecuteUpdateSql(szSql, -1)
    '        SaveMatBM = cnt

    '    End With
    'End Function

    Public Function GetEquipMatPush(ByVal szOLDEquipID As String, ByVal szEquipID As String,
                                     ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                     ByVal szTable As String, ByVal szItem As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   MAT.INOUT_{0}_TEMP AS INOUT_TEMP, MAT.INOUT_{0}_TIME AS INOUT_TIME, MAT.INOUT_{0}_VDD AS INOUT_VDD, "
        szSql &= "   MAT.INOUT_{0}_VCC AS INOUT_VCC, MAT.INOUT_{0}_VPP AS INOUT_VPP, MAT.INOUT_{0}_BOARD_NO AS INOUT_BOARD_NO, "
        szSql &= "   MAT.INOUT_{0}_MATRIX AS INOUT_MATRIX, MAT.INOUT_BI_ID, "
        szSql &= "   SV2.INOUT_BI_ID AS INOUT_EQUIP_NO, SV2.INOUT_BOARD_QTY, SV2.INOUT_ONE_BOARD "
        szSql = String.Format(szSql, szItem)

        szSql &= SqlCondCom(szOLDEquipID, szEquipID, szLotNo, Status, szTable)

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPush = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPush = dt
        End If
    End Function

    ''' <summary>
    ''' 着脱治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatInOut(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                        ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                        ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                        ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                        ByVal szTable As String, ByVal szItem As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PUSH "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = String.Format("INSERT INTO MAT.{0}( ", szTable)
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  INOUT_{0}_TEMP, INOUT_{0}_TIME, INOUT_{0}_VDD, "
            szSql &= "  INOUT_{0}_VCC, INOUT_{0}_VPP, INOUT_{0}_BOARD_NO, "
            szSql &= "  INOUT_{0}_MATRIX, "
            szSql &= "  INOUT_BI_ID, INOUT_BOARD_QTY, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql = String.Format(szSql, szItem)
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', " &
                                   "'{12}', '{13}', " &
                                   "'{14}', '{15}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("INOUT_TEMP"), .Item("INOUT_TIME"), .Item("INOUT_BOARD_QTY"),
                                  .Item("INOUT_VCC"), .Item("INOUT_VPP"), .Item("INOUT_BOARD_NO"),
                                  .Item("INOUT_MATRIX"),
                                  .Item("INOUT_BI_ID"), .Item("INOUT_BOARD_QTY"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatInOut = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = String.Format("INSERT INTO MAT.{0}( ", szTable)
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  INOUT_BI_ID, INOUT_BOARD_QTY, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("INOUT_BI_ID"), .Item("INOUT_BOARD_QTY"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatInOut = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatPull(ByVal szOLDEquipID As String, ByVal szEquipID As String,
                                     ByVal szLotNo As String, ByVal Status As TagProcessStatus,
                                     ByVal szTable As String, ByVal szItem As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   MAT.INOUT_{0}_TEMP AS INOUT_TEMP, MAT.INOUT_{0}_TIME AS INOUT_TIME, MAT.INOUT_{0}_VDD AS INOUT_VDD, "
        szSql &= "   MAT.INOUT_{0}_VCC AS INOUT_VCC, MAT.INOUT_{0}_VPP AS INOUT_VPP, MAT.INOUT_{0}_BOARD_NO AS INOUT_BOARD_NO, "
        szSql &= "   MAT.INOUT_{0}_MATRIX AS INOUT_MATRIX, MAT.INOUT_BI_ID, "
        szSql &= "   SAV.INOUT_BI_ID AS INOUT_EQUIP_NO, SAV.INOUT_BOARD_QTY, SV2.INOUT_ONE_BOARD "
        szSql = String.Format(szSql, szItem)

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, szTable, szTable.Replace("LL", "SH"))

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPull = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPull = dt
        End If
    End Function


    Public Function GetEquipMatBist(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.BIST_TEMP , SV2.BIST_VDD, "
        szSql &= "   SV2.BIST_VPP, SV2.BIST_MATRIX, "
        szSql &= "   SV2.BIST_RANGE, SAV.BI_A_RANGE AS BIST_RANGE_ORG, SAV.BI_A_BI_ID AS BIST_BI_ID, "
        szSql &= "   SAV.BI_A_BOARD_NO AS BIST_BOARD_NO, '' AS BIST_A_TEMP "

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_BIST", "L_EQUIP_MAT_FT_BARIN")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatBist = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatBist = dt
        End If
    End Function


    Public Function GetEquipMatHS(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.SELF_CHECK, "
        szSql &= "  SV2.HS_LOT_NO, SV2.HS_PASTE_LOT "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_HS")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatHS = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatHS = dt
        End If
    End Function

    ''' <summary>
    ''' WB前プラズマ治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatHS(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_HS "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        'With dtEquipMat.Rows(1)
        '    szSql = ""
        '    szSql = "INSERT INTO MAT.L_EQUIP_MAT_HS( "
        '    szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
        '    szSql &= "  HS_LOT_NO, HS_PASTE_LOT, "
        '    szSql &= "  BEGIN_TIME, BEGIN_OPT "
        '    szSql &= ") "
        '    szSql &= "VALUES ( "
        '    szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " & _
        '                           "'{5}', '{6}', " & _
        '                           "'{7}', '{8}'", _
        '                          szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD, _
        '                          .Item("HS_LOT_NO"), .Item("HS_PASTE_LOT"), _
        '                         dte, szBeginOpt)
        '    szSql &= ")"

        '    cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        '    UpdateEquipMatHS = cnt
        '    If cnt < 0 Then
        '        DBacs.RollbackTransaction()
        '        Exit Function
        '    End If

        'End With

        With dtEquipMat.Rows(0)
            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_HS( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  HS_LOT_NO, HS_PASTE_LOT, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("HS_LOT_NO"), .Item("HS_PASTE_LOT"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatHS = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveHS(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szHsLot As String, ByVal szPasteLot As String) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_HS "
        szSql &= "SET "
        szSql &= "  HS_LOT_NO ='" & szHsLot & "', "
        szSql &= "  HS_PASTE_LOT ='" & szPasteLot & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function


    ''' <summary>
    ''' BIST治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatBist(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                        ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                        ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                        ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        '製造条件を保存
        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_BIST( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  BIST_TEMP, BIST_VDD, BIST_VPP, BIST_MATRIX, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', " &
                                   "'{9}', '{10}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BIST_TEMP"), .Item("BIST_VDD"), .Item("BIST_VPP"), .Item("BIST_MATRIX"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBist = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        szSql = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_BIST "
        szSql &= "SET "
        szSql &= "  SYS_EQUIP_ID='{0}', "
        szSql &= "  EQUIP_NO='{1}', "
        szSql &= "  KOUTEI_CD='{2}', "
        szSql &= "  BIST_TEMP='{3}', "
        szSql &= "  BIST_VDD='{4}', "
        szSql &= "  BIST_VPP='{5}', "
        szSql &= "  BIST_MATRIX='{6}', "
        szSql &= "  BIST_RANGE='{7}', "
        szSql &= "  BIST_BI_ID='{8}', "
        szSql &= "  BIST_BOARD_NO='{9}', "
        szSql &= "  BIST_A_TEMP='{10}', "
        szSql &= "  BEGIN_TIME='{11}', "
        szSql &= "  BEGIN_OPT='{12}' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND BEGIN_OPT = '' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        With dtEquipMat.Rows(0)
            szSql = String.Format(szSql,
                                  szSysEquipID, szEquipNo, szProcCD,
                                  .Item("BIST_TEMP"), .Item("BIST_VDD"), .Item("BIST_VPP"), .Item("BIST_MATRIX"),
                                  .Item("BIST_RANGE"), .Item("BIST_BI_ID"), .Item("BIST_BOARD_NO"), .Item("BIST_A_TEMP"),
                                 dte, szBeginOpt)
        End With

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
        UpdateEquipMatBist = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        ElseIf cnt = 0 Then
            '記録された詰範囲が存在しない場合
            With dtEquipMat.Rows(0)
                szSql = ""
                szSql &= "UPDATE MAT.L_EQUIP_MAT_BIST "
                szSql &= "SET "
                'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
                'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
                szSql &= "  IS_DONE = TRUE "
                szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
                szSql &= "AND LOT_NO='" & szLotNo & "' "
                szSql &= "AND IS_CONDITION=FALSE "

                DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
                UpdateEquipMatBist = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If

                szSql = "INSERT INTO MAT.L_EQUIP_MAT_BIST( "
                szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
                szSql &= "  BIST_TEMP, BIST_VDD, BIST_VPP, BIST_MATRIX, "
                szSql &= "  BIST_RANGE, BIST_BI_ID, BIST_BOARD_NO, BIST_A_TEMP, "
                szSql &= "  BEGIN_TIME, BEGIN_OPT "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                       "'{5}', '{6}', '{7}', '{8}', " &
                                       "'{9}', '{10}', '{11}', '{12}', " &
                                       "'{13}', '{14}'",
                                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                      .Item("BIST_TEMP"), .Item("BIST_VDD"), .Item("BIST_VPP"), .Item("BIST_MATRIX"),
                                      .Item("BIST_RANGE"), .Item("BIST_BI_ID"), .Item("BIST_BOARD_NO"), .Item("BIST_A_TEMP"),
                                     dte, szBeginOpt)
                szSql &= ")"

                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                UpdateEquipMatBist = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If
            End With
        End If

        DBacs.CommitTransaction()
    End Function

    ''' <summary>
    ''' 詰範囲を保存する
    ''' </summary>
    ''' <param name="szLotNo"></param>
    ''' <param name="szOldEquipID"></param>
    ''' <param name="szEquipID"></param>
    ''' <param name="szRange2"></param>
    ''' <returns>更新された行数</returns>
    ''' <remarks></remarks>
    Public Function SaveBistRange(ByVal szLotNo As String, ByVal szOldEquipID As String, ByVal szEquipID As String,
                                ByVal szRange2 As String, Optional ByVal dteBeginTM As DateTime = Nothing) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        szSql &= "UPDATE MAT.L_EQUIP_MAT_BIST "
        szSql &= "SET "
        szSql &= "  BIST_RANGE = '" & szRange2 & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        If IsNothing(dteBeginTM) OrElse dteBeginTM = DateTime.MinValue Then
            szSql &= "AND BEGIN_OPT = '' "
        Else
            szSql &= "AND BEGIN_TIME = ? "
        End If
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, dteBeginTM)
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Return cnt
        ElseIf cnt = 0 Then
            If Not IsNothing(dteBeginTM) AndAlso Not dteBeginTM = DateTime.MinValue Then
                DBacs.RollbackTransaction()
                Return -10
            End If
            '古い記録のクリア
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_BIST "
            szSql &= "SET "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            szSql &= "AND IS_CONDITION=FALSE "

            cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            End If

            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_BIST( "
            szSql &= "  EQUIP_ID, LOT_NO, "
            szSql &= "  BIST_RANGE "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', " &
                                   "'{2}'",
                                  szEquipID, szLotNo,
                                  szRange2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            Else
                SaveBistRange = cnt
            End If
        Else
            SaveBistRange = cnt
        End If

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatErase(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.ERASE_TEMP , SV2.ERASE_VDD, "
        szSql &= "   SV2.ERASE_VPP, SV2.ERASE_MATRIX, "
        szSql &= "   SV2.ERASE_RANGE, SAV.INOUT_BI_ID AS ERASE_BI_ID, "
        szSql &= "   SV2.ERASE_BOARD_NO "

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_ERASE", "L_EQUIP_MAT_E_PUSH")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatErase = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatErase = dt
        End If
    End Function

    ''' <summary>
    ''' 消去治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatErase(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                        ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                        ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                        ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        '製造条件を保存
        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_ERASE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  ERASE_TEMP, ERASE_VDD, ERASE_VPP, ERASE_MATRIX, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', " &
                                   "'{9}', '{10}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("ERASE_TEMP"), .Item("ERASE_VDD"), .Item("ERASE_VPP"), .Item("ERASE_MATRIX"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatErase = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        szSql = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_ERASE "
        szSql &= "SET "
        szSql &= "  SYS_EQUIP_ID='{0}', "
        szSql &= "  EQUIP_NO='{1}', "
        szSql &= "  KOUTEI_CD='{2}', "
        szSql &= "  ERASE_TEMP='{3}', "
        szSql &= "  ERASE_VDD='{4}', "
        szSql &= "  ERASE_VPP='{5}', "
        szSql &= "  ERASE_MATRIX='{6}', "
        szSql &= "  ERASE_RANGE='{7}', "
        szSql &= "  ERASE_BI_ID='{8}', "
        szSql &= "  ERASE_BOARD_NO='{9}', "
        szSql &= "  BEGIN_TIME='{10}', "
        szSql &= "  BEGIN_OPT='{11}' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND BEGIN_OPT = '' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        With dtEquipMat.Rows(0)
            szSql = String.Format(szSql,
                                  szSysEquipID, szEquipNo, szProcCD,
                                  .Item("ERASE_TEMP"), .Item("ERASE_VDD"), .Item("ERASE_VPP"), .Item("ERASE_MATRIX"),
                                  .Item("ERASE_RANGE"), .Item("ERASE_BI_ID"), .Item("ERASE_BOARD_NO"),
                                 dte, szBeginOpt)
        End With

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
        UpdateEquipMatErase = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        ElseIf cnt = 0 Then
            '記録された詰範囲が存在しない場合
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_ERASE "
            szSql &= "SET "
            'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
            'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            szSql &= "AND IS_CONDITION=FALSE "

            DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            UpdateEquipMatErase = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

            With dtEquipMat.Rows(0)
                szSql = "INSERT INTO MAT.L_EQUIP_MAT_ERASE( "
                szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
                szSql &= "  ERASE_TEMP, ERASE_VDD, ERASE_VPP, ERASE_MATRIX, "
                szSql &= "  ERASE_RANGE, ERASE_BI_ID, ERASE_BOARD_NO, "
                szSql &= "  BEGIN_TIME, BEGIN_OPT "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                       "'{5}', '{6}', '{7}', '{8}', " &
                                       "'{9}', '{10}', '{11}', " &
                                       "'{12}', '{13}'",
                                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                      .Item("ERASE_TEMP"), .Item("ERASE_VDD"), .Item("ERASE_VPP"), .Item("ERASE_MATRIX"),
                                      .Item("ERASE_RANGE"), .Item("ERASE_BI_ID"), .Item("ERASE_BOARD_NO"),
                                     dte, szBeginOpt)
                szSql &= ")"

                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                UpdateEquipMatErase = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If

            End With
        End If

        DBacs.CommitTransaction()
    End Function

    ''' <summary>
    ''' 詰範囲を保存する
    ''' </summary>
    ''' <param name="szLotNo"></param>
    ''' <param name="szOldEquipID"></param>
    ''' <param name="szEquipID"></param>
    ''' <param name="szRange3"></param>
    ''' <returns>更新された行数</returns>
    ''' <remarks></remarks>
    Public Function SaveEraseRange(ByVal szLotNo As String, ByVal szOldEquipID As String, ByVal szEquipID As String,
                                ByVal szRange3 As String, ByVal szBoard As String, Optional ByVal dteBeginTM As DateTime = Nothing) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        szSql &= "UPDATE MAT.L_EQUIP_MAT_ERASE "
        szSql &= "SET "
        szSql &= "  ERASE_RANGE = '" & szRange3 & "', "
        szSql &= "  ERASE_BOARD_NO = '" & szBoard & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        If IsNothing(dteBeginTM) OrElse dteBeginTM = DateTime.MinValue Then
            szSql &= "AND BEGIN_OPT = '' "
        Else
            szSql &= "AND BEGIN_TIME = ? "
        End If
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, dteBeginTM)
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Return cnt
        ElseIf cnt = 0 Then
            If Not IsNothing(dteBeginTM) AndAlso Not dteBeginTM = DateTime.MinValue Then
                DBacs.RollbackTransaction()
                Return -10
            End If
            '古い記録のクリア
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_ERASE "
            szSql &= "SET "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            szSql &= "AND IS_CONDITION=FALSE "

            cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            End If

            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_ERASE( "
            szSql &= "  EQUIP_ID, LOT_NO, "
            szSql &= "  ERASE_RANGE,ERASE_BOARD_NO "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', " &
                                   "'{2}', '{3}'",
                                  szEquipID, szLotNo,
                                  szRange3, szBoard)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            Else
                SaveEraseRange = cnt
            End If
        Else
            SaveEraseRange = cnt
        End If

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatRepair(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.REPAIR_TEMP , SV2.REPAIR_VDD, "
        szSql &= "   SV2.REPAIR_VPP, SV2.REPAIR_MATRIX, "
        szSql &= "   SA2.BI_A_RANGE AS REPAIR_RANGE, SA1.INOUT_BI_ID AS REPAIR_BI_ID, "
        szSql &= "   SA2.BI_A_BOARD_NO AS REPAIR_BOARD_NO, SV2.REPAIR_A_TEMP "

        szSql &= SqlCondLastTime2(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_REPAIR", "L_EQUIP_MAT_PUSH", "L_EQUIP_MAT_FT_BARIN")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatRepair = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatRepair = dt
        End If
    End Function

    ''' <summary>
    ''' 消去治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatRepair(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                        ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                        ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                        ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        '製造条件を保存
        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_REPAIR( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  REPAIR_TEMP, REPAIR_VDD, REPAIR_VPP, REPAIR_MATRIX, REPAIR_A_TEMP, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("REPAIR_TEMP"), .Item("REPAIR_VDD"), .Item("REPAIR_VPP"), .Item("REPAIR_MATRIX"), .Item("REPAIR_A_TEMP"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatRepair = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        szSql = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_REPAIR "
        szSql &= "SET "
        szSql &= "  SYS_EQUIP_ID='{0}', "
        szSql &= "  EQUIP_NO='{1}', "
        szSql &= "  KOUTEI_CD='{2}', "
        szSql &= "  REPAIR_TEMP='{3}', "
        szSql &= "  REPAIR_VDD='{4}', "
        szSql &= "  REPAIR_VPP='{5}', "
        szSql &= "  REPAIR_MATRIX='{6}', "
        szSql &= "  REPAIR_RANGE='{7}', "
        szSql &= "  REPAIR_BI_ID='{8}', "
        szSql &= "  REPAIR_BOARD_NO='{9}', "
        szSql &= "  REPAIR_A_TEMP='{10}', "
        szSql &= "  BEGIN_TIME='{11}', "
        szSql &= "  BEGIN_OPT='{12}' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND BEGIN_OPT = '' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        With dtEquipMat.Rows(0)
            szSql = String.Format(szSql,
                                  szSysEquipID, szEquipNo, szProcCD,
                                  .Item("REPAIR_TEMP"), .Item("REPAIR_VDD"), .Item("REPAIR_VPP"), .Item("REPAIR_MATRIX"),
                                  .Item("REPAIR_RANGE"), .Item("REPAIR_BI_ID"), .Item("REPAIR_BOARD_NO"), .Item("REPAIR_A_TEMP"),
                                 dte, szBeginOpt)
        End With

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
        UpdateEquipMatRepair = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        ElseIf cnt = 0 Then
            '記録された詰範囲が存在しない場合
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_REPAIR "
            szSql &= "SET "
            'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
            'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            szSql &= "AND IS_CONDITION=FALSE "

            DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            UpdateEquipMatRepair = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

            With dtEquipMat.Rows(0)
                szSql = "INSERT INTO MAT.L_EQUIP_MAT_REPAIR( "
                szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
                szSql &= "  REPAIR_TEMP, REPAIR_VDD, REPAIR_VPP, REPAIR_MATRIX, REPAIR_A_TEMP, "
                szSql &= "  REPAIR_RANGE, REPAIR_BI_ID, REPAIR_BOARD_NO, "
                szSql &= "  BEGIN_TIME, BEGIN_OPT "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                       "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                       "'{10}', '{11}', '{12}', " &
                                       "'{13}', '{14}'",
                                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                      .Item("REPAIR_TEMP"), .Item("REPAIR_VDD"), .Item("REPAIR_VPP"), .Item("REPAIR_MATRIX"),
                                      .Item("REPAIR_RANGE"), .Item("REPAIR_BI_ID"), .Item("REPAIR_BOARD_NO"), .Item("REPAIR_A_TEMP"),
                                     dte, szBeginOpt)
                szSql &= ")"

                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                UpdateEquipMatRepair = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If

            End With
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatFtg(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus, ByVal szTable As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  SV2.FTG_MAGZINE, SV2.FTG_FULL_SHIP, SV2.FTG_STORAGE, "
        szSql &= "  SV2.FTG_SPECIAL, SV2.FTG_LABEL, SV2.FTG_WEEK_CD, "
        szSql &= "  SV2.FTG_PUSH1, SV2.FTG_PULL1, "
        szSql &= "  SV2.FTG_PUSH2, SV2.FTG_PULL2 "
        szSql &= SqlCondLot(szOldEquipID, szEquipID, szLotNo, Status, szTable, szTable)

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatFtg = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatFtg = dt
        End If
    End Function

    Public Function UpdateEquipMatFtg(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                      ByVal szSysEquipID As String, ByVal szEquipNo As String, ByVal szProcCD As String,
                                      ByVal dtEquipMat As DataTable, ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                      ByVal szTable As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = String.Format("INSERT INTO MAT.{0}( ", szTable)
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  FTG_MAGZINE, FTG_FULL_SHIP, "
            szSql &= "  FTG_STORAGE, FTG_SPECIAL, "
            szSql &= "  FTG_LABEL, FTG_WEEK_CD, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT  "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', " &
                                   "'{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("FTG_MAGZINE"), .Item("FTG_FULL_SHIP"),
                                  .Item("FTG_STORAGE"), .Item("FTG_SPECIAL"),
                                  .Item("FTG_LABEL"), .Item("FTG_WEEK_CD"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatFtg = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = String.Format("INSERT INTO MAT.{0}( ", szTable)
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  FTG_MAGZINE, FTG_WEEK_CD, "
            szSql &= "  FTG_PUSH1, FTG_PULL1, "
            szSql &= "  FTG_PUSH2, FTG_PULL2, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT  "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', " &
                                   "'{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("FTG_MAGZINE"), .Item("FTG_WEEK_CD"),
                                  .Item("FTG_PUSH1"), .Item("FTG_PULL1"),
                                  .Item("FTG_PUSH2"), .Item("FTG_PULL2"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatFtg = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function
    ' 蘇州対応 2017/04/10 T.Yutaro Upd Start
    'Public Function SaveFtgExtraInOut(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szEx1() As String, ByVal szEx2() As String, ByVal szTable As String) As Integer
    Public Function SaveFtgExtraInOut(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szEx1() As String, ByVal szEx2() As String, ByVal szTable As String, ByVal htFinish As Hashtable) As Integer
        ' 蘇州対応 2017/04/10 T.Yutaro Upd End

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  FTG_PUSH1 ='" & szEx1(0) & "', "
        szSql &= "  FTG_PULL1 ='" & szEx1(1) & "', "
        szSql &= "  FTG_PUSH2 ='" & szEx2(0) & "', "
        ' 蘇州対応 2017/04/10 T.Yutaro Upd Start
        'szSql &= "  FTG_PULL2 ='" & szEx2(1) & "' "
        szSql &= "  FTG_PULL2 ='" & szEx2(1) & "', "
        szSql &= "  FTG_FAIL_RATE ='" & htFinish("FTG_FAIL_RATE") & "', "
        szSql &= "  FTG_P_MANAGE ='" & htFinish("FTG_P_MANAGE") & "', "
        szSql &= "  FTG_MARK ='" & htFinish("FTG_MARK") & "', "
        szSql &= "  FTG_FAIL_NUM_MARK ='" & htFinish("FTG_FAIL_NUM_MARK") & "', "
        szSql &= "  FTG_FAIL_NUM_LEAD ='" & htFinish("FTG_FAIL_NUM_LEAD") & "', "
        szSql &= "  FTG_FAIL_NUM_MAT ='" & htFinish("FTG_FAIL_NUM_MAT") & "' "
        ' 蘇州対応 2017/04/10 T.Yutaro Upd End
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatTaping(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  MAT.TAPING_CUSTOMER, MAT.TAPING_LOT_MERGE, MAT.TAPING_MAGZINE, "
        szSql &= "  MAT.TAPING_STOPPER, MAT.TAPING_BOX, MAT.TAPING_STORAGE, "
        szSql &= "  MAT.TAPING_LABEL, MAT.TAPING_NAME, MAT.TAPING_SOURCE, "
        szSql &= "  SAV.FTG_PUSH1 AS TAPING_PUSH1, SAV.FTG_PULL1 AS TAPING_PULL1, "
        szSql &= "  SAV.FTG_PUSH2 AS TAPING_PUSH2, SAV.FTG_PULL2 AS TAPING_PULL2 "
        szSql &= SqlCondLastTime(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_TAPING", "L_EQUIP_MAT_FT_GAIKAN1")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatTaping = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatTaping = dt
        End If
    End Function

    Public Function UpdateEquipMatTaping(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                          ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                          ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                          ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_TAPING "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TAPING( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  TAPING_CUSTOMER, TAPING_LOT_MERGE, TAPING_MAGZINE, "
            szSql &= "  TAPING_STOPPER, TAPING_BOX, TAPING_STORAGE, "
            szSql &= "  TAPING_LABEL, TAPING_NAME, TAPING_SOURCE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT  "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}', '{13}', " &
                                   "'{14}', '{15}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TAPING_CUSTOMER"), .Item("TAPING_LOT_MERGE"), .Item("TAPING_MAGZINE"),
                                  .Item("TAPING_STOPPER"), .Item("TAPING_BOX"), .Item("TAPING_STORAGE"),
                                  .Item("TAPING_LABEL"), .Item("TAPING_NAME"), .Item("TAPING_SOURCE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTaping = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TAPING( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  TAPING_PUSH1, TAPING_PULL1, "
            szSql &= "  TAPING_PUSH2, TAPING_PULL2, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT  "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', " &
                                   "'{9}', '{10}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TAPING_PUSH1"), .Item("TAPING_PULL1"),
                                  .Item("TAPING_PUSH2"), .Item("TAPING_PULL2"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTaping = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatPacking(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  SV2.PACKING_MAGZINE, SV2.PACKING_STOPPER, SV2.PACKING_BOX, "
        szSql &= "  MAT.PACKING_FULL_SHIP, MAT.PACKING_STORAGE, MAT.PACKING_SPECIAL, "
        szSql &= "  MAT.PACKING_LABEL, MAT.PACKING_NAME, MAT.PACKING_SOURCE, "
        szSql &= "  SAV.FTG_PUSH1 AS PACKING_PUSH1, SAV.FTG_PULL1 AS PACKING_PULL1, "
        szSql &= "  SAV.FTG_PUSH2 AS PACKING_PUSH2, SAV.FTG_PULL2 AS PACKING_PULL2 "
        szSql &= SqlCondLastTime(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_PACKING", "L_EQUIP_MAT_FT_GAIKAN1")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPacking = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPacking = dt
        End If
    End Function

    Public Function UpdateEquipMatPacking(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                          ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                          ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                          ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PACKING "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PACKING( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  PACKING_MAGZINE, PACKING_STOPPER, PACKING_BOX, "
            szSql &= "  PACKING_FULL_SHIP, PACKING_STORAGE, PACKING_SPECIAL, "
            szSql &= "  PACKING_LABEL, PACKING_NAME, PACKING_SOURCE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT  "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}', '{13}', " &
                                   "'{14}', '{15}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PACKING_MAGZINE"), .Item("PACKING_STOPPER"), .Item("PACKING_BOX"),
                                  .Item("PACKING_FULL_SHIP"), .Item("PACKING_STORAGE"), .Item("PACKING_SPECIAL"),
                                  .Item("PACKING_LABEL"), .Item("PACKING_NAME"), .Item("PACKING_SOURCE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPacking = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PACKING( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  PACKING_MAGZINE, PACKING_STOPPER, PACKING_BOX, "
            szSql &= "  PACKING_PUSH1, PACKING_PULL1, "
            szSql &= "  PACKING_PUSH2, PACKING_PULL2, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT  "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', " &
                                   "'{10}', '{11}', " &
                                   "'{12}', '{13}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PACKING_MAGZINE"), .Item("PACKING_STOPPER"), .Item("PACKING_BOX"),
                                  .Item("PACKING_PUSH1"), .Item("PACKING_PULL1"),
                                  .Item("PACKING_PUSH2"), .Item("PACKING_PULL2"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPacking = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatBI(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.BI_A_TEMP, SV2.BI_A_TIME, SV2.BI_A_VDD, "
        szSql &= "   SV2.BI_A_VCC, SV2.BI_A_VPP, SV2.BI_A_BOARD_NO, "
        szSql &= "   SV2.BI_A_MATRIX, SV2.BI_A_RANGE, "
        szSql &= "   SV2.BI_A_BOARD_QTY AS NEW_BOARD_QTY, "
        'szSql &= "   SV2.BI_B_TEMP, SV2.BI_B_VDD, SV2.BI_B_VPP, SV2.BI_B_MATRIX, SV2.BI_B_RANGE, "
        'szSql &= "   SV2.BI_E_TEMP, SV2.BI_E_VDD, SV2.BI_E_VPP, SV2.BI_E_MATRIX, SV2.BI_E_RANGE, "
        szSql &= "   SAV.INOUT_BI_ID AS BI_A_BI_ID, SV2.BI_BAKE, "
        szSql &= "   SAV.INOUT_BOARD_QTY AS BI_A_BOARD_QTY "
        szSql &= SqlCondLastTime(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_FT_BARIN", "L_EQUIP_MAT_PUSH")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatBI = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatBI = dt
        End If
    End Function

    Public Function UpdateEquipMatBI(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                     ByVal szSysEquipID As String, ByVal szEquipNo As String, ByVal szProcCD As String,
                                     ByVal dtEquipMat As DataTable, ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                     ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        '製造条件を保存
        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_FT_BARIN( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  BI_A_TEMP, BI_A_TIME, BI_A_VDD, "
            szSql &= "  BI_A_VCC, BI_A_VPP, BI_A_BOARD_NO, "
            szSql &= "  BI_A_MATRIX, BI_A_RANGE, " 'BI_B_TEMP, BI_B_VDD, "
            'szSql &= "  BI_B_VPP, BI_B_MATRIX, BI_B_RANGE, BI_E_TEMP, "
            'szSql &= "  BI_E_VDD, BI_E_VPP, BI_E_MATRIX, BI_E_RANGE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}', " &
                                   "'{13}', '{14}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BI_A_TEMP"), .Item("BI_A_TIME"), .Item("BI_A_VDD"),
                                  .Item("BI_A_VCC"), .Item("BI_A_VPP"), .Item("BI_A_BOARD_NO"),
                                  .Item("BI_A_MATRIX"), .Item("BI_A_RANGE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBI = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        szSql = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_BARIN "
        szSql &= "SET "
        szSql &= "  SYS_EQUIP_ID='{0}', "
        szSql &= "  EQUIP_NO='{1}', "
        szSql &= "  KOUTEI_CD='{2}', "
        szSql &= "  BI_A_TEMP='{3}', "
        szSql &= "  BI_A_TIME='{4}', "
        szSql &= "  BI_A_VDD='{5}', "
        szSql &= "  BI_A_VCC='{6}', "
        szSql &= "  BI_A_VPP='{7}', "
        szSql &= "  BI_A_BOARD_NO='{8}', "
        szSql &= "  BI_A_MATRIX='{9}', "
        szSql &= "  BI_A_RANGE='{10}', "
        szSql &= "  BI_A_BI_ID='{11}', "
        szSql &= "  BI_A_BOARD_QTY='{12}', "
        'szSql &= "  BI_B_TEMP='{13}', "
        'szSql &= "  BI_B_VDD='{14}', "
        'szSql &= "  BI_B_VPP='{15}', "
        'szSql &= "  BI_B_MATRIX='{16}', "
        'szSql &= "  BI_B_RANGE='{17}', "
        'szSql &= "  BI_E_TEMP='{18}', "
        'szSql &= "  BI_E_VDD='{19}', "
        'szSql &= "  BI_E_VPP='{20}', "
        'szSql &= "  BI_E_MATRIX='{21}', "
        'szSql &= "  BI_E_RANGE='{22}', "
        szSql &= "  BEGIN_TIME='{13}', "
        szSql &= "  BEGIN_OPT='{14}' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND BEGIN_OPT = '' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        With dtEquipMat.Rows(0)
            szSql = String.Format(szSql,
                                  szSysEquipID, szEquipNo, szProcCD,
                                  .Item("BI_A_TEMP"), .Item("BI_A_TIME"), .Item("BI_A_VDD"), .Item("BI_A_VCC"),
                                  .Item("BI_A_VPP"), .Item("BI_A_BOARD_NO"), .Item("BI_A_MATRIX"), .Item("BI_A_RANGE"),
                                  .Item("BI_A_BI_ID"), .Item("BI_A_BOARD_QTY"),
                                 dte, szBeginOpt)
        End With

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
        UpdateEquipMatBI = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        ElseIf cnt = 0 Then
            '記録された詰範囲が存在しない場合
            With dtEquipMat.Rows(0)

                szSql = ""
                szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_BARIN "
                szSql &= "SET "
                'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
                'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
                szSql &= "  IS_DONE = TRUE "
                szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
                szSql &= "AND LOT_NO='" & szLotNo & "' "
                szSql &= "AND IS_CONDITION=FALSE "

                cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
                UpdateEquipMatBI = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If

                szSql = "INSERT INTO MAT.L_EQUIP_MAT_FT_BARIN( "
                szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
                szSql &= "  BI_A_TEMP, BI_A_TIME, BI_A_VDD, BI_A_VCC, "
                szSql &= "  BI_A_VPP, BI_A_BOARD_NO, BI_A_MATRIX, BI_A_RANGE, "
                szSql &= "  BI_A_BI_ID, BI_A_BOARD_QTY, "
                szSql &= "  BEGIN_TIME, BEGIN_OPT "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                       "'{5}', '{6}', '{7}', '{8}', " &
                                       "'{9}', '{10}', '{11}', '{12}', " &
                                       "'{13}', '{14}', " &
                                       "'{15}', '{16}'",
                                      szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                      .Item("BI_A_TEMP"), .Item("BI_A_TIME"), .Item("BI_A_VDD"), .Item("BI_A_VCC"),
                                      .Item("BI_A_VPP"), .Item("BI_A_BOARD_NO"), .Item("BI_A_MATRIX"), .Item("BI_A_RANGE"),
                                      .Item("BI_A_BI_ID"), .Item("BI_A_BOARD_QTY"),
                                     dte, szBeginOpt)
                szSql &= ")"

                cnt = DBacs.ExecuteUpdateSql(szSql, -1)
                UpdateEquipMatBI = cnt
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Exit Function
                End If

            End With
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function SaveBiBoard(ByVal szLotNo As String, ByVal szEquipID As String, ByVal iBoardQty As Integer, ByVal szBiNo As String, ByVal szRange As String) As Integer
        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_BARIN "
        szSql &= "SET "
        szSql &= "  BI_A_BOARD_QTY ='" & iBoardQty.ToString & "', "
        szSql &= "  BI_A_RANGE ='" & szRange & "', "
        szSql &= "  BI_A_BI_ID ='" & szBiNo & "' "
        szSql &= "WHERE LOT_NO='" & szLotNo & "' "
        szSql &= "AND EQUIP_ID = '" & szEquipID & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szLotNo)
    End Function

    Public Function SaveBoardQty(ByVal szLotNo As String, ByVal szEquipID As String, ByVal iBoardQty As Integer, ByVal szBiNo As String, ByVal szOneBoard As String, ByVal szTable As String) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  INOUT_BOARD_QTY ='" & iBoardQty.ToString & "', "
        If Not String.IsNullOrEmpty(szOneBoard) Then
            szSql &= "  INOUT_ONE_BOARD ='" & szOneBoard & "', "
        End If
        szSql &= "  INOUT_BI_ID ='" & szBiNo & "' "
        szSql &= "WHERE LOT_NO='" & szLotNo & "' "
        szSql &= "AND EQUIP_ID = '" & szEquipID & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szLotNo)
    End Function

    ''' <summary>
    ''' 詰範囲を保存する
    ''' </summary>
    ''' <param name="szLotNo"></param>
    ''' <param name="szOldEquipID"></param>
    ''' <param name="szEquipID"></param>
    ''' <param name="szRange1"></param>
    ''' <returns>更新された行数</returns>
    ''' <remarks></remarks>
    Public Function SaveBiRange(ByVal szLotNo As String, ByVal szOldEquipID As String, ByVal szEquipID As String,
                                ByVal szRange1 As String, ByVal szQty1 As String, Optional ByVal dteBeginTM As DateTime = Nothing) As Integer
        DBacs.BeginTransaction()

        Dim cnt As Integer
        Dim szSql As String = ""

        szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_BARIN "
        szSql &= "SET "
        szSql &= "  BI_A_RANGE = '" & szRange1 & "', "
        szSql &= "  BI_A_BOARD_QTY = '" & szQty1 & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        If IsNothing(dteBeginTM) OrElse dteBeginTM = DateTime.MinValue Then
            szSql &= "AND BEGIN_OPT = '' "
        Else
            szSql &= "AND BEGIN_TIME = ? "
        End If
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        cnt = DBacs.ExecuteUpdateSql(szSql, -1, dteBeginTM)
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Return cnt
        ElseIf cnt = 0 Then
            If Not IsNothing(dteBeginTM) AndAlso Not dteBeginTM = DateTime.MinValue Then
                DBacs.RollbackTransaction()
                Return -10
            End If
            '古い記録のクリア
            szSql = ""
            szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_BARIN "
            szSql &= "SET "
            szSql &= "  IS_DONE = TRUE "
            szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            szSql &= "AND IS_CONDITION=FALSE "

            cnt = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            End If

            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_FT_BARIN( "
            szSql &= "  EQUIP_ID, LOT_NO, "
            szSql &= "  BI_A_RANGE, BI_A_BOARD_QTY "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', " &
                                   "'{2}', '{3}'",
                                  szEquipID, szLotNo,
                                  szRange1, szQty1)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Return cnt
            Else
                SaveBiRange = cnt
            End If
        Else
            SaveBiRange = cnt
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatBAKE(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "  SV2.BAKE_PLATE, SV2.BAKE_TEMP, SAV.MOLD_RACK AS BAKE_RACK0, "
        szSql &= "  SV2.BAKE_RACK1, SV2.BAKE_RACK2, SV2.BAKE_RACK3, SV2.BAKE_RACK4, "
        szSql &= "  SV2.BAKE_RACK5, SV2.BAKE_RACK6, SV2.BAKE_RACK7, SV2.BAKE_RACK8 "
        szSql &= SqlCondLastTime(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_MOLD_AFC", "L_EQUIP_MAT_MOLD")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatBAKE = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatBAKE = dt
        End If
    End Function

    Public Function UpdateEquipMatBAKE(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                       ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MOLD_AFC "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MOLD_AFC( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  BAKE_PLATE, BAKE_TEMP, "
            szSql &= "  BAKE_RACK1, BAKE_RACK2, "
            szSql &= "  BAKE_RACK3, BAKE_RACK4, "
            szSql &= "  BAKE_RACK5, BAKE_RACK6, "
            szSql &= "  BAKE_RACK7, BAKE_RACK8, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            szSql &= "  BAKE_MEMO1, BAKE_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}', '{13}', '{14}', " &
                                   "'{15}', '{16}', " &
                                   "'{17}', '{18}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BAKE_PLATE"), .Item("BAKE_TEMP"),
                                  .Item("BAKE_RACK1"), .Item("BAKE_RACK2"), .Item("BAKE_RACK3"), .Item("BAKE_RACK4"),
                                  .Item("BAKE_RACK5"), .Item("BAKE_RACK6"), .Item("BAKE_RACK7"), .Item("BAKE_RACK8"),
                                 dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBAKE = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MOLD_AFC( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  BAKE_PLATE, BAKE_TEMP, "
            szSql &= "  BAKE_RACK1, BAKE_RACK2, "
            szSql &= "  BAKE_RACK3, BAKE_RACK4, "
            szSql &= "  BAKE_RACK5, BAKE_RACK6, "
            szSql &= "  BAKE_RACK7, BAKE_RACK8, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}', '{13}', '{14}', " &
                                   "'{15}', '{16}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BAKE_PLATE"), .Item("BAKE_TEMP"),
                                  .Item("BAKE_RACK1"), .Item("BAKE_RACK2"), .Item("BAKE_RACK3"), .Item("BAKE_RACK4"),
                                  .Item("BAKE_RACK5"), .Item("BAKE_RACK6"), .Item("BAKE_RACK7"), .Item("BAKE_RACK8"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBAKE = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatBistBake(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.BIST_BK_COND, SV2.BIST_BK_PLATE "

        szSql &= SqlCondCom(szOLDEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_BIST_BAKE")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatBistBake = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatBistBake = dt
        End If
    End Function

    ''' <summary>
    ''' BISTベーク治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatBistBake(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                         ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_BIST_BAKE "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_BIST_BAKE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  BIST_BK_COND, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BIST_BK_PLATE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBistBake = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_BIST_BAKE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  BIST_BK_COND, BIST_BK_PLATE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("BIST_BK_COND"), .Item("BIST_BK_PLATE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatBistBake = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    'ベークの中身をクリア
    Public Function ClearBakeRack(ByVal szEquipID As String, ByVal szLotNo As String) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MOLD_AFC "
        szSql &= "SET "
        szSql &= "  BAKE_RACK1 ='', "
        szSql &= "  BAKE_RACK2 ='', "
        szSql &= "  BAKE_RACK3 ='', "
        szSql &= "  BAKE_RACK4 ='', "
        szSql &= "  BAKE_RACK5 ='', "
        szSql &= "  BAKE_RACK6 ='', "
        szSql &= "  BAKE_RACK7 ='', "
        szSql &= "  BAKE_RACK8 ='' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatFTT0(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szProcCD As String,
                                   ByVal szLotNo As String, ByVal Status As TagProcessStatus, ByVal fTestFlag As Boolean) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.FTT_A_TEMP, SV2.FTT_FAIL_RP, '' AS FTT_LIMIT_TIME, "
        szSql &= "   SV2.FTT_T_PATH, SV2.FTT_H_PATH, SV2.FTT_P_MNG, "
        szSql &= "   '' AS LAST_TIME "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_FT_TEST0")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatFTT0 = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatFTT0 = dt
        End If
    End Function

    Public Function UpdateEquipMatFTT0(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                      ByVal szSysEquipID As String, ByVal szEquipNo As String, ByVal szProcCD As String,
                                      ByVal dtEquipMat As DataTable, ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_TEST0 "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_FT_TEST0( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  FTT_A_TEMP, FTT_FAIL_RP, FTT_T_PATH, FTT_H_PATH, FTT_P_MNG, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("FTT_A_TEMP"), .Item("FTT_FAIL_RP"), .Item("FTT_T_PATH"), .Item("FTT_H_PATH"), .Item("FTT_P_MNG"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatFTT0 = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_FT_TEST0( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  FTT_A_TEMP, FTT_FAIL_RP, FTT_T_PATH, FTT_H_PATH, FTT_P_MNG, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', '{8}', '{9}', " &
                                   "'{10}', '{11}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("FTT_A_TEMP"), .Item("FTT_FAIL_RP"), .Item("FTT_T_PATH"), .Item("FTT_H_PATH"), .Item("FTT_P_MNG"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatFTT0 = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveEquipMatFTT0(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTP As String, ByVal szHP As String, ByVal szPM As String) As Integer
        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_FT_TEST0 "
        szSql &= "SET "
        szSql &= "  FTT_T_PATH ='" & szTP & "', "
        szSql &= "  FTT_H_PATH ='" & szHP & "', "
        szSql &= "  FTT_P_MNG ='" & szPM & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        SaveEquipMatFTT0 = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetFlowAndComplete(ByVal szLotNo As String, ByVal szProc As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT KOMOKUDATA AS PROC, '' AS QTY "
        szSql &= "FROM PER.L_JYOKENDATA "
        szSql &= "WHERE KLOTNO = '" & szLotNo & "' "
        szSql &= "AND KOMOKUDATA IS NOT NULL "
        szSql &= "AND KOMOKUNAME LIKE '" & szProc & "作業ﾌﾛｰ%' "
        szSql &= "AND KOMOKUNAME NOT LIKE '%No%' "
        szSql &= "ORDER BY TO_NUMBER(REPLACE(REPLACE(KOMOKUNAME, '" & szProc & "作業ﾌﾛｰ', ''),'_','.'), '99.9')  "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szLotNo)
        If Not IsNothing(dt) AndAlso dt.Rows.Count > 0 Then

            szSql = "SELECT COMPLETE_QTY FROM MAT.L_EQUIP_MAT_HEADER "
            szSql &= "WHERE LOT_NO='" & szLotNo & "' "
            szSql &= "AND KOUTEI_CD ='{0}' "
            szSql &= "ORDER BY SYS_CMD_ID DESC "
            szSql &= "LIMIT 1 "

            With dt
                For Each dr As DataRow In .Rows
                    Dim szProcCD As String = ProcNM2ProcCD(dr("PROC").ToString)

                    If Not String.IsNullOrEmpty(szProcCD) Then
                        Dim dtComp As DataTable = DBacs.ExecuteSql(String.Format(szSql, szProcCD))
                        If Not IsNothing(dtComp) AndAlso dtComp.Rows.Count > 0 AndAlso Not IsDBNull(dtComp.Rows(0)(0)) Then
                            dr("QTY") = dtComp.Rows(0)(0)
                        Else
                            dr("QTY") = String.Empty
                        End If
                    End If
                Next
            End With

            GetFlowAndComplete = dt
        Else
            GetFlowAndComplete = New DataTable
        End If
    End Function

    Public Const DIECING As String = "ﾀﾞｲｼﾝｸﾞ"
    Public Const ASSEMBLY As String = "組立"
    Public Const SEAL As String = "封止・先切り"
    Public Const MARK As String = "マーク・メッキ・成形"
    Public Const SELECTION As String = "選別"
    Public Const PACKING As String = "外観・梱包"

    Private Function ProcNM2ProcCD(ByVal szProcNm As String) As String
        Select Case szProcNm
            'ﾀﾞｲｼﾝｸﾞ
            Case "ウエハ受入"
                ProcNM2ProcCD = PROC_CD_WAFER
            Case "テープ貼付"
                ProcNM2ProcCD = PROC_CD_TAPE
            Case "ダイシング"
                ProcNM2ProcCD = PROC_CD_DIESER
            Case "バーコード貼付"
                ProcNM2ProcCD = PROC_CD_BARCODE
            Case "テープUV"
                ProcNM2ProcCD = PROC_CD_TAPE_UV
            Case "テープＵＶ"
                ProcNM2ProcCD = PROC_CD_TAPE_UV
            Case "ウエハ貼付"
                ProcNM2ProcCD = ""
            Case "治具詰"
                ProcNM2ProcCD = ""
            Case "PQC"
                ProcNM2ProcCD = ""
            Case "メインD/B"
                ProcNM2ProcCD = ""
            Case "外観検査"
                ProcNM2ProcCD = PROC_CD_DIC_CHK
            Case "FlashD/B(DAF)"
                ProcNM2ProcCD = ""
            Case "梱包・払出"
                ProcNM2ProcCD = ""


                '組立
            Case "D/B"
                ProcNM2ProcCD = PROC_CD_DBS
            Case "D/B+C/C"
                ProcNM2ProcCD = PROC_CD_DBS
            Case "SDD/B(DAF)"
                ProcNM2ProcCD = ""
            Case "ペ付け"
                ProcNM2ProcCD = ""
            Case "C/C(ベークキュア)"
                ProcNM2ProcCD = PROC_CD_DBAFC
            Case "キュア"
                ProcNM2ProcCD = PROC_CD_DBAFC
            Case "ベーク"
                ProcNM2ProcCD = PROC_CD_DBAFC
            Case "ベークキュア"
                ProcNM2ProcCD = PROC_CD_DBAFC
            Case "ペ付け2"
                ProcNM2ProcCD = ""
            Case "枚葉ベーク"
                ProcNM2ProcCD = ""
            Case "P/C"
                ProcNM2ProcCD = PROC_CD_PLASMA_WB
            Case "P/C150"
                ProcNM2ProcCD = PROC_CD_PLASMA_WB
            Case "W/B"
                ProcNM2ProcCD = PROC_CD_WBS
            Case "W/B1"
                ProcNM2ProcCD = PROC_CD_WBS
            Case "W/B前P/C"
                ProcNM2ProcCD = PROC_CD_PLASMA_WB
            Case "W/B2"
                ProcNM2ProcCD = PROC_CD_WBS '2
            Case "外観検査"
                'ProcNM2ProcCD = PROC_CD_INSP

                '封止・先切り
            Case "P/C"
                ProcNM2ProcCD = PROC_CD_PLASMA_MD
            Case "P/C3"
                ProcNM2ProcCD = PROC_CD_PLASMA_MD
            Case "モールド"
                ProcNM2ProcCD = PROC_CD_MOLDS
            Case "ベーク"
                ProcNM2ProcCD = PROC_CD_MOLD_AFC
            Case "X線検査"
                ProcNM2ProcCD = PROC_CD_XSEN
            Case "ベーク+外観検査"
                ProcNM2ProcCD = PROC_CD_MOLDQC
            Case "自動X線検査"
                ProcNM2ProcCD = ""
            Case "先切り"
                ProcNM2ProcCD = ""

                'マーク・メッキ・成形
            Case "デフラッシュ"
                ProcNM2ProcCD = ""
            Case "レーザーマーク"
                ProcNM2ProcCD = PROC_CD_MARK
            Case "B/M+リフロー"
                ProcNM2ProcCD = PROC_CD_BALL
            Case "メッキ"
                ProcNM2ProcCD = ""
            Case "前処理Y1"
                ProcNM2ProcCD = ""
            Case "洗浄"
                ProcNM2ProcCD = PROC_CD_WASH
            Case "ベーク"
                ProcNM2ProcCD = PROC_CD_HS_BAKE
            Case "(UV)マーク"
                ProcNM2ProcCD = ""
            Case "P/C"
                ProcNM2ProcCD = PROC_CD_HS_PLASMA
            Case "テープ貼付"
                ProcNM2ProcCD = PROC_CD_SHEET
            Case "個片切断"
                ProcNM2ProcCD = PROC_CD_KOHEN_DIESER
            Case "切断成形"
                ProcNM2ProcCD = PROC_CD_KOHEN_DIESER
            Case "HS貼付け"
                ProcNM2ProcCD = PROC_CD_HS
            Case "PKGダイシング"
                ProcNM2ProcCD = PROC_CD_KOHEN_DIESER
            Case "トラベルシート発行"
                ProcNM2ProcCD = ""
            Case "ピックアップ"
                ProcNM2ProcCD = PROC_CD_PIXTUKA

                '選別
            Case "0DC+FT"
                ProcNM2ProcCD = PROC_CD_FT_TEST0
            Case "基板詰め"
                ProcNM2ProcCD = PROC_CD_PUSH
            Case "イニシャル"
                ProcNM2ProcCD = ""
            Case "エージング"
                ProcNM2ProcCD = PROC_CD_FT_BARIN
            Case "基板抜き"
                ProcNM2ProcCD = PROC_CD_PULL
            Case "1EA選"
                ProcNM2ProcCD = PROC_CD_EA_TESTER
            Case "1DC+FT"
                ProcNM2ProcCD = PROC_CD_FT_TEST1
            Case "2DC+FT"
                ProcNM2ProcCD = PROC_CD_FT_TEST2
            Case "3DC+FT"
                ProcNM2ProcCD = PROC_CD_FT_TEST3

                '外観・梱包
            Case "ベーク"
                ProcNM2ProcCD = ""
            Case "最終外観検査"
                ProcNM2ProcCD = PROC_CD_FT_GAIKAN_FINAL
            Case "自動外観検査"
                ProcNM2ProcCD = ""
            Case "外観検査機"
                ProcNM2ProcCD = ""
            Case "ロット分割"
                ProcNM2ProcCD = ""
            Case "ロット合成"
                ProcNM2ProcCD = ""
            Case "チェック"
                ProcNM2ProcCD = PROC_CD_CHECK
            Case "追加ベーク"
                ProcNM2ProcCD = ""
            Case "ロット分割合成"
                ProcNM2ProcCD = ""
            Case "防湿梱包"
                ProcNM2ProcCD = ""
            Case "テープ&リール"
                ProcNM2ProcCD = PROC_CD_TAPING
            Case "出荷梱包"
                ProcNM2ProcCD = PROC_CD_HAKO
            Case Else
                ProcNM2ProcCD = String.Empty
        End Select
    End Function

    Public Function GetTestComplete(ByVal szLotNo As String) As DataTable
        Dim i As Integer
        Dim szSql As String = ""
        szSql &= "SELECT "
        szSql &= "  "
        For i = 1 To 22
            szSql &= "FLOW" & i.ToString & ", "
        Next
        szSql &= "FLOW23 "
        szSql &= "FROM ( "
        szSql &= "  SELECT KLOTNO AS LOT_NO,"
        For i = 1 To 22
            szSql &= String.Format("    ARRAY_TO_STRING(ARRAY_AGG(CASE WHEN KOMOKUNAME='選別作業ﾌﾛｰ{0}' THEN KOMOKUDATA ELSE '' END),'') AS FLOW{0}, ", i)
        Next
        szSql &= "    ARRAY_TO_STRING(ARRAY_AGG(CASE WHEN KOMOKUNAME='選別作業ﾌﾛｰ23' THEN KOMOKUDATA ELSE '' END),'') AS FLOW23 "
        szSql &= "  FROM PER.L_JYOKENDATA "
        szSql &= "  WHERE KLOTNO = '" & szLotNo & "' "
        szSql &= "  GROUP BY KLOTNO "
        szSql &= ") AS T"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szLotNo)
        If Not IsNothing(dt) AndAlso dt.Rows.Count > 0 Then

            szSql = "SELECT COMPLETE_QTY FROM MAT.L_EQUIP_MAT_HEADER "
            szSql &= "WHERE LOT_NO='" & szLotNo & "' "
            szSql &= "AND KOUTEI_CD ='{0}' "
            szSql &= "ORDER BY SYS_CMD_ID DESC "
            szSql &= "LIMIT 1 "

            With dt
                Dim newRow As DataRow = dt.NewRow

                For Each col As DataColumn In .Columns
                    Dim szProcCD As String = String.Empty
                    Select Case .Rows(0)(col.Caption).ToString
                        Case "0DC+FT"
                            szProcCD = "M050"
                        Case "基板詰め"
                            szProcCD = "M100"
                            'Case "イニシャル"
                            '    szProcCD = ""
                        Case "エージング"
                            szProcCD = "M200"
                        Case "基板抜き"
                            szProcCD = "M500"
                        Case "1EA選"
                            szProcCD = "M450"
                        Case "1DC+FT"
                            szProcCD = "N200"
                        Case "2DC+FT"
                            szProcCD = "N300"
                        Case "3DC+FT"
                            szProcCD = "N400"
                    End Select

                    If Not String.IsNullOrEmpty(szProcCD) Then
                        Dim dtComp As DataTable = DBacs.ExecuteSql(String.Format(szSql, szProcCD))
                        If Not IsNothing(dtComp) AndAlso dtComp.Rows.Count > 0 AndAlso Not IsDBNull(dtComp.Rows(0)(0)) Then
                            newRow(col.Caption) = dtComp.Rows(0)(0)
                        Else
                            newRow(col.Caption) = String.Empty
                        End If
                    End If
                Next
                dt.Rows.Add(newRow)
            End With

            GetTestComplete = dt
        Else
            GetTestComplete = New DataTable
        End If
    End Function

    Public Function GetEquipMatFTT(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szProcCD As String,
                                   ByVal szLotNo As String, ByVal Status As TagProcessStatus, ByVal fTestFlag As Boolean, ByVal szTable As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   MAT.FTT_A_TEMP, MAT.FTT_FAIL_RP, MAT.FTT_LIMIT_TIME, "
        szSql &= "   SV2.FTT_T_PATH, SV2.FTT_H_PATH, SV2.FTT_P_MNG, "
        szSql &= "   P0.FTT_T_PATH AS T_PATH0, P0.FTT_H_PATH AS H_PATH0, P0.FTT_P_MNG AS P_MNG0, "
        szSql &= "   P1.FTT_T_PATH AS T_PATH1, P1.FTT_H_PATH AS H_PATH1, P1.FTT_P_MNG AS P_MNG1, "
        szSql &= "   P2.FTT_T_PATH AS T_PATH2, P2.FTT_H_PATH AS H_PATH2, P2.FTT_P_MNG AS P_MNG2, "
        If fTestFlag Then
            szSql &= "   '' AS LAST_TIME "
            szSql &= SqlCondFttFlg(szOldEquipID, szEquipID, szProcCD, szLotNo, Status, szTable)
        Else
            szSql &= "   TO_CHAR(SAV.TOTAL_TIME, 'YYYY/MM/DD HH24:MI:SS') AS LAST_TIME "
            szSql &= SqlCondFtt(szOldEquipID, szEquipID, szProcCD, szLotNo, Status, szTable)
        End If

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatFTT = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatFTT = dt
        End If
    End Function

    Public Function UpdateEquipMatFTT(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                      ByVal szSysEquipID As String, ByVal szEquipNo As String, ByVal szProcCD As String,
                                      ByVal dtEquipMat As DataTable, ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                      ByVal szTable As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = String.Format("INSERT INTO MAT.{0} ( ", szTable)
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  FTT_A_TEMP, FTT_FAIL_RP, FTT_LIMIT_TIME, "
            szSql &= "  FTT_T_PATH, FTT_H_PATH, FTT_P_MNG, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("FTT_A_TEMP"), .Item("FTT_FAIL_RP"), .Item("FTT_LIMIT_TIME"),
                                  .Item("FTT_T_PATH"), .Item("FTT_H_PATH"), .Item("FTT_P_MNG"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatFTT = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
        End With

        With dtEquipMat.Rows(0)
            szSql = String.Format("INSERT INTO MAT.{0} ( ", szTable)
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  FTT_A_TEMP, FTT_FAIL_RP, FTT_LIMIT_TIME, "
            szSql &= "  FTT_T_PATH, FTT_H_PATH, FTT_P_MNG, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("FTT_A_TEMP"), .Item("FTT_FAIL_RP"), .Item("FTT_LIMIT_TIME"),
                                  .Item("FTT_T_PATH"), .Item("FTT_H_PATH"), .Item("FTT_P_MNG"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatFTT = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveEquipMatFTT(ByVal szEquipID As String, ByVal szLotNo As String,
                                    ByVal szTP As String, ByVal szHP As String, ByVal szPM As String, ByVal szTable As String) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  FTT_T_PATH ='" & szTP & "', "
        szSql &= "  FTT_H_PATH ='" & szHP & "', "
        szSql &= "  FTT_P_MNG ='" & szPM & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        SaveEquipMatFTT = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatMark(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.SELF_CHECK, SV2.TRIAL_CHECK, "
        szSql &= "  SV2.MARK_NAME, SV2.MARK_WEEK_CD, SV2.MARK_LOT_NO, "
        szSql &= "  SV2.MARK_NO, SV2.MARK_LOT1, SV2.MARK_LOT2 "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_MARK")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatMark = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatMark = dt
        End If
    End Function

    Public Function UpdateEquipMatMark(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                       ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MARK "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MARK( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  MARK_NAME, MARK_WEEK_CD, MARK_LOT_NO, "
            szSql &= "  MARK_NO, MARK_LOT1, MARK_LOT2, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT, "
            szSql &= "  MARK_MEMO1, MARK_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}', " &
                                   "'{13}', '{14}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("MARK_NAME"), .Item("MARK_WEEK_CD"), .Item("MARK_LOT_NO"),
                                  .Item("MARK_NO"), .Item("MARK_LOT1"), .Item("MARK_LOT2"),
                                 dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMark = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MARK( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  MARK_NAME, MARK_WEEK_CD, MARK_LOT_NO, "
            szSql &= "  MARK_NO, MARK_LOT1, MARK_LOT2, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("MARK_NAME"), .Item("MARK_WEEK_CD"), .Item("MARK_LOT_NO"),
                                  .Item("MARK_NO"), .Item("MARK_LOT1"), .Item("MARK_LOT2"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMark = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveMarkConfirm(ByVal szLotNo As String, ByVal szEquipID As String, ByVal szConfirm() As String) As Integer
        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MARK "
        szSql &= "SET "
        szSql &= "  MARK_NAME ='" & szConfirm(0) & "', "
        szSql &= "  MARK_WEEK_CD ='" & szConfirm(1) & "', "
        szSql &= "  MARK_LOT_NO ='" & szConfirm(2) & "', "
        szSql &= "  MARK_NO ='" & szConfirm(3) & "', "
        szSql &= "  MARK_LOT1 ='" & szConfirm(4) & "', "
        szSql &= "  MARK_LOT2 ='" & szConfirm(5) & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        SaveMarkConfirm = DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatPkgDic(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.SELF_CHECK, SV2.SIDE_CHECK, "
        szSql &= "  MAT.PKGDIC_FRAME, MAT.PKGDIC_MOLD1, "
        szSql &= "  MAT.PKGDIC_MOLD2, MAT.PKGDIC_THICK, "
        szSql &= "  MAT.PKGDIC_TRAY, MAT.PKGDIC_BLADE "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_KOHEN_DIESER")


        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPkgDic = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPkgDic = dt
        End If
    End Function

    ''' <summary>
    ''' パッケージダイシング治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatPkgDic(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_KOHEN_DIESER "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_KOHEN_DIESER( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  PKGDIC_FRAME, PKGDIC_MOLD1, "
            szSql &= "  PKGDIC_MOLD2, PKGDIC_THICK, "
            szSql &= "  PKGDIC_TRAY, PKGDIC_BLADE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}', " &
                                   "'{9}', '{10}', " &
                                   "'{11}', '{12}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PKGDIC_FRAME"), .Item("PKGDIC_MOLD1"),
                                  .Item("PKGDIC_MOLD2"), .Item("PKGDIC_THICK"),
                                  .Item("PKGDIC_TRAY"), .Item("PKGDIC_BLADE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPkgDic = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_KOHEN_DIESER( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  PKGDIC_TRAY, PKGDIC_BLADE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', " &
                                   "'{7}', '{8}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PKGDIC_TRAY"), .Item("PKGDIC_BLADE"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPkgDic = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveBlade(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szBlade As String, ByVal szTable As String) As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  PKGDIC_BLADE ='" & szBlade & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function


    Public Function GetEquipMatPickUp(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.SELF_CHECK, SV2.SIDE_CHECK, "
        szSql &= "  SV2.PICK_UP_TRAY "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_PICK_UP")


        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatPickUp = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatPickUp = dt
        End If
    End Function

    ''' <summary>
    ''' パッケージダイシング治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatPickUp(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                         ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                         ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                         ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PICK_UP "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PICK_UP( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  PICK_UP_TRAY, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PICK_UP_TRAY"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPickUp = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PICK_UP( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  PICK_UP_TRAY, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PICK_UP_TRAY"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatPickUp = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function


    Public Function GetEquipMatTrim(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                    ByVal Status As TagProcessStatus) As DataTable

        Dim szSql As String = ""

        szSql &= "SELECT SV2.CROSS_QTY, SV2.TRIM_CHECK, SV2.SELF_CHECK, "
        szSql &= "SV2.TRIM_MEMO1, SV2.TRIM_MEMO2 "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_TRIM")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatTrim = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatTrim = dt
        End If

    End Function

    ''' <summary>
    ''' 切断系治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatTrim(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_TRIM "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TRIM( "
            szSql &= "SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "TRIM_CHECK, "
            szSql &= "BEGIN_TIME, BEGIN_OPT, "
            szSql &= "TRIM_MEMO1, TRIM_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{6}', '{7}', " &
                                   "'{8}', '{9}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TRIM_CHECK"),
                                  dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTrim = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_TRIM( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  TRIM_CHECK, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TRIM_CHECK"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTrim = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatTemp(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                 ByVal Status As TagProcessStatus) As DataTable

        Dim szSql As String = ""

        szSql &= "SELECT SV2.CROSS_QTY, SV2.TEMP_CYCLE, SV2.CHECK_QTY, "
        szSql &= "SV2.TEMP_MEMO1, SV2.TEMP_MEMO2 "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_TEMP")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatTemp = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatTemp = dt
        End If

    End Function

    ''' <summary>
    ''' 温度サイクル治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatTemp(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_TEMP "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_TEMP( "
            szSql &= "SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "TEMP_CYCLE, "
            szSql &= "BEGIN_TIME, BEGIN_OPT, "
            szSql &= "TEMP_MEMO1, TEMP_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{6}', '{7}', " &
                                   "'{8}', '{9}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TEMP_CYCLE"),
                                  dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTemp = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_TEMP( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  TEMP_CYCLE, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("TEMP_CYCLE"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatTemp = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatAutoX(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                 ByVal Status As TagProcessStatus) As DataTable

        Dim szSql As String = ""

        szSql &= "SELECT SV2.CROSS_QTY, SV2.AUTOX_CHECK, SV2.CHECK_QTY, "
        szSql &= "SV2.AUTOX_MEMO1, SV2.AUTOX_MEMO2 "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_AUTOX")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatAutoX = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatAutoX = dt
        End If

    End Function

    ''' <summary>
    ''' 自動X線治工具の保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="szSysEquipID"></param>
    ''' <param name="szEquipNo">装置No</param>
    ''' <param name="dtEquipMat">治工具情報テーブル</param>
    ''' <param name="szBeginTM">着工開始時間</param>
    ''' <param name="szBeginOpt">開始作業者</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateEquipMatAutoX(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                           ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                           ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                           ByRef szBeginTM As DateTime, ByVal szBeginOpt As String,
                                           ByVal szMemo1 As String, ByVal szMemo2 As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_AUTOX "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = ""
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_AUTOX( "
            szSql &= "SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "AUTOX_CHECK, "
            szSql &= "BEGIN_TIME, BEGIN_OPT, "
            szSql &= "AUTOX_MEMO1, AUTOX_MEMO2 "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{6}', '{7}', " &
                                   "'{8}', '{9}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("AUTOX_CHECK"),
                                  dte, szBeginOpt,
                                  szMemo1, szMemo2)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatAutoX = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = ""
            szSql &= "INSERT INTO MAT.L_EQUIP_MAT_AUTOX( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  AUTOX_CHECK, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("AUTOX_CHECK"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatAutoX = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function GetEquipMatMeki(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.SELF_CHECK, SV2.PLATE_BALL1, "
        szSql &= "  SV2.PLATE_BALL2, SV2.PLATE_FRM, CND.PLATE_DUMY, CND.PLATE_RACK "
        szSql &= SqlCondCond(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_PLATE")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatMeki = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatMeki = dt
        End If

    End Function

    Public Function UpdateEquipMatMeki(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PLATE "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLATE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  PLATE_BALL1, PLATE_BALL2, PLATE_FRM, "
            szSql &= "  PLATE_DUMY, PLATE_RACK, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', " &
                                   "'{10}', '{11}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PLATE_BALL1"), .Item("PLATE_BALL2"), .Item("PLATE_FRM"),
                                  .Item("PLATE_DUMY"), .Item("PLATE_RACK"),
                                 dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMeki = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_PLATE( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  PLATE_BALL1, PLATE_BALL2, PLATE_FRM, "
            szSql &= "  PLATE_DUMY, PLATE_RACK, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', " &
                                   "'{10}', '{11}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("PLATE_BALL1"), .Item("PLATE_BALL2"), .Item("PLATE_FRM"),
                                  .Item("PLATE_DUMY"), .Item("PLATE_RACK"),
                                 dte, szBeginOpt)
            szSql &= ")"


            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMeki = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveMeki(ByVal szEquipID As String, ByVal szLotNo As String,
                               ByVal szDummy As String, ByVal szRack As String, ByVal dteTime As DateTime) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_PLATE "
        szSql &= "SET "
        szSql &= "  PLATE_DUMY ='" & szDummy & "', "
        szSql &= "  PLATE_RACK ='" & szRack & "', "
        szSql &= "  PLATE_COMPTIME ='" & dteTime & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function GetEquipMatLtf(ByVal szOldEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, SV2.TRIAL_CHECK, SV2.CHECK_QTY, SV2.LTF_BALL1, SV2.LTF_BALL2, SV2.LTF_FRM, "
        szSql &= "  MAT.LTF_MOLD1, MAT.LTF_MOLD2, MAT.LTF_MOLD3, MAT.LTF_MOLD4, MAT.LTF_MOLD5, "
        szSql &= "  SV2.LTF_PKG, SV2.LTF_SPEC_S, SV2.LTF_TRAY, SV2.LTF_TRAVEL "
        szSql &= SqlCondCom(szOldEquipID, szEquipID, szLotNo, Status, "L_EQUIP_MAT_LTF")

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatLtf = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatLtf = dt
        End If

    End Function

    Public Function UpdateEquipMatLtf(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_LTF "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_LTF( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  LTF_BALL1, LTF_BALL2, LTF_FRM, LTF_PKG, "
            szSql &= "  LTF_SPEC_S, LTF_TRAY, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', '{6}', '{7}', '{8}', " &
                                   "'{9}', '{10}', " &
                                   "'{11}', '{12}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("LTF_BALL1"), .Item("LTF_BALL2"), .Item("LTF_FRM"), .Item("LTF_PKG"),
                                  .Item("LTF_SPEC_S"), .Item("LTF_TRAY"),
                                 dte, szBeginOpt)
            szSql &= ")"
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatLtf = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_LTF( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  LTF_BALL1, LTF_BALL2, LTF_FRM, "
            szSql &= "  LTF_MOLD1, LTF_MOLD2, LTF_MOLD3, LTF_MOLD4, LTF_MOLD5, "
            szSql &= "  LTF_PKG, LTF_SPEC_S, LTF_TRAY, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', '{6}', '{7}', " &
                                   "'{8}', '{9}', '{10}', '{11}', '{12}', " &
                                   "'{13}', '{14}', '{15}', " &
                                   "'{16}', '{17}' ",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("LTF_BALL1"), .Item("LTF_BALL2"), .Item("LTF_FRM"),
                                  .Item("LTF_MOLD1"), .Item("LTF_MOLD2"), .Item("LTF_MOLD3"), .Item("LTF_MOLD4"), .Item("LTF_MOLD5"),
                                  .Item("LTF_PKG"), .Item("LTF_SPEC_S"), .Item("LTF_TRAY"),
                                 dte, szBeginOpt)
            szSql &= ")"


            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatLtf = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
        End With

        DBacs.CommitTransaction()
    End Function



    ''' <summary>
    ''' 製造完成情報保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="dteTime">完成時間</param>
    ''' <param name="szOpt">完成作業者</param>
    ''' <returns>更新された行数</returns>
    ''' <remarks></remarks>
    Public Function SaveCompleteInfo(ByVal szEquipID As String, ByVal szLotNo As String,
                                     ByRef dteTime As String, ByVal szOpt As String,
                                     ByVal szTable As String, ByVal dtHeader As DataTable,
                                 Optional ByVal szCheck As String = "",
                                 Optional ByVal szSelfCheck As String = "",
                                 Optional ByVal szTrialCheck As String = "",
                                 Optional ByVal szSideCheck As String = "",
                                 Optional ByVal szChgFrame As String = "",
                                 Optional ByVal szChgBall As String = "",
                                 Optional ByVal szCross As String = "") As Integer
        DBacs.BeginTransaction()
        Dim iCnt As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        If Not String.IsNullOrEmpty(szCheck) Then
            szSql &= "  CHECK_QTY  ='" & szCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szSelfCheck) Then
            szSql &= "  SELF_CHECK  ='" & szSelfCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szTrialCheck) Then
            szSql &= "  TRIAL_CHECK ='" & szTrialCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szSideCheck) Then
            szSql &= "  SIDE_CHECK ='" & szSideCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szChgFrame) Then
            szSql &= "  CHG_FRAME ='" & szChgFrame & "', "
        End If
        If Not String.IsNullOrEmpty(szChgBall) Then
            szSql &= "  CHG_BALL ='" & szChgBall & "', "
        End If
        szSql &= "  CROSS_QTY ='" & szCross & "', "
        szSql &= "  COMPLETE_TIME =NOW(), "
        szSql &= "  COMPLETE_OPT ='" & szOpt & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "
        szSql &= "RETURNING BEGIN_TIME, COMPLETE_TIME "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql)
        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            dtHeader.Rows(0)("COMPLETE_TIME") = dt.Rows(0)(1)
            dteTime = dt.Rows(0)(1)
        End If

        iCnt = UpdateHeader(dtHeader, frmStartCompleteBase.ProcessStatus.ManufComplete,
                                           szLotNo, szEquipID, dt.Rows(0)(0))
        If iCnt < 0 Then
            DBacs.RollbackTransaction()
            Return iCnt
        End If

        DBacs.CommitTransaction()
        Return iCnt
    End Function

    ' 蘇州対応 2017/04/28 T.Yutaro Add Start
    Public Function SaveCompleteInfo_Self_Chk_Qty(ByVal szEquipID As String, ByVal szLotNo As String,
                                     ByVal szTable As String, ByVal selfChkQty As String) As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  SELF_CHECK_QTY ='" & selfChkQty & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

    End Function
    ' 蘇州対応 2017/04/28 T.Yutaro Add End
    ''' <summary>
    ''' 計上完成情報保存
    ''' </summary>
    ''' <param name="szEquipID">装置ID</param>
    ''' <param name="szLotNo">ロットNo</param>
    ''' <param name="dteTime">完成時間</param>
    ''' <param name="szOpt">完成作業者</param>
    ''' <returns>更新された行数</returns>
    ''' <remarks></remarks>
    Public Function SaveTotalInfo(ByVal szEquipID As String, ByVal szLotNo As String,
                                  ByRef dteTime As DateTime, ByVal szOpt As String,
                                  ByVal szTable As String, ByVal dtHeader As DataTable,
                                 Optional ByVal szCheck As String = "",
                                 Optional ByVal szSelfCheck As String = "",
                                 Optional ByVal szTrialCheck As String = "",
                                 Optional ByVal szSideCheck As String = "",
                                 Optional ByVal szChgFrame As String = "",
                                 Optional ByVal szChgBall As String = "",
                                 Optional ByVal szCross As String = "") As Integer
        DBacs.BeginTransaction()
        Dim iCnt As Integer

        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        If Not String.IsNullOrEmpty(szCheck) Then
            szSql &= "  CHECK_QTY  ='" & szCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szSelfCheck) Then
            szSql &= "  SELF_CHECK  ='" & szSelfCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szTrialCheck) Then
            szSql &= "  TRIAL_CHECK ='" & szTrialCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szSideCheck) Then
            szSql &= "  SIDE_CHECK ='" & szSideCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szChgFrame) Then
            szSql &= "  CHG_FRAME ='" & szChgFrame & "', "
        End If
        If Not String.IsNullOrEmpty(szChgBall) Then
            szSql &= "  CHG_BALL ='" & szChgBall & "', "
        End If
        szSql &= "  CROSS_QTY ='" & szCross & "', "
        ' 蘇州対応 2017/05/08 T.Yutaro Add Start
        szSql &= "  COMPLETE_TIME = (CASE WHEN COMPLETE_TIME IS NULL THEN NOW() ELSE COMPLETE_TIME END), "
        szSql &= "  COMPLETE_OPT = (CASE WHEN COMPLETE_OPT IS NULL THEN '" & szOpt & "' ELSE COMPLETE_OPT END), "
        ' 蘇州対応 2017/05/08 T.Yutaro Add End
        szSql &= "  TOTAL_TIME =NOW(), "
        szSql &= "  TOTAL_OPT ='" & szOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "
        szSql &= "RETURNING BEGIN_TIME, TOTAL_TIME "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql)
        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            dtHeader.Rows(0)("TOTAL_TIME") = dt.Rows(0)(1)
            dteTime = dt.Rows(0)(1)
        End If

        iCnt = UpdateHeader(dtHeader, frmStartCompleteBase.ProcessStatus.TotalComplete,
                                           szLotNo, szEquipID, dt.Rows(0)(0))
        If iCnt < 0 Then
            DBacs.RollbackTransaction()
            Return iCnt
        End If

        DBacs.CommitTransaction()
        Return iCnt
    End Function

    Public Function SaveQty(ByVal szLotNo As String, ByVal szEquipID As String, ByVal szTable As String,
                                 Optional ByVal szCheck As String = "",
                                 Optional ByVal szSelfCheck As String = "",
                                 Optional ByVal szTrialCheck As String = "",
                                 Optional ByVal szSideCheck As String = "",
                                 Optional ByVal szChgFrame As String = "",
                                 Optional ByVal szChgBall As String = "",
                                 Optional ByVal szCross As String = "") As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        If Not String.IsNullOrEmpty(szCheck) Then
            szSql &= "  CHECK_QTY  ='" & szCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szSelfCheck) Then
            szSql &= "  SELF_CHECK  ='" & szSelfCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szTrialCheck) Then
            szSql &= "  TRIAL_CHECK ='" & szTrialCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szSideCheck) Then
            szSql &= "  SIDE_CHECK ='" & szSideCheck & "', "
        End If
        If Not String.IsNullOrEmpty(szChgFrame) Then
            szSql &= "  CHG_FRAME ='" & szChgFrame & "', "
        End If
        If Not String.IsNullOrEmpty(szChgBall) Then
            szSql &= "  CHG_BALL ='" & szChgBall & "', "
        End If
        szSql &= "  CROSS_QTY ='" & szCross & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    Public Function LotCancel(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTable As String, ByVal dtHeader As DataTable) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = False "
        szSql &= "AND IS_CONDITION=FALSE "
        szSql &= "RETURNING BEGIN_TIME "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql)
        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            DBacs.RollbackTransaction()
            Return -10
        End If

        Dim iCnt As Integer = UpdateHeader(dtHeader, frmStartCompleteBase.ProcessStatus.Canceled,
                                           szLotNo, szEquipID, dt.Rows(0)(0))
        If iCnt < 0 Then
            DBacs.RollbackTransaction()
            Return iCnt
        End If

        DBacs.CommitTransaction()
        Return iCnt
    End Function


    Public Function GetHeader(ByVal szLotNo As String, ByVal szEquipID As String, ByVal szProcCD As String, ByVal szBeginTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM MAT.L_SF_WORK_RSLT_HEAD "
        'szSql &= "SELECT * FROM MAT.L_SF_WORK_RSLT_HEAD "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        'szSql &= "AND KOUTEI_CD = '" & szProcCD & "' "
        szSql &= "AND BEGIN_TIME = '" & szBeginTime & "' "

        GetHeader = DBacs.ExecuteSql(szSql, -1)
    End Function


    Public Function SaveHeader(ByVal dtHeader As DataTable, ByRef count As Integer,
                                  ByVal szLotNo As String, ByVal szEquipID As String, ByVal type As String, ByVal szDteBegin As String) As DateTime
        Dim szSql As String = ""
        'Dim dte As DateTime

        'szSql = "SELECT NOW()"
        'Dim dtDate As DataTable = DBacs.ExecuteSql(szSql)
        'dte = CDate(dtDate.Rows(0)(0))

        With dtHeader.Rows(0)
            szSql = ""
            szSql &= "SELECT MAX(PROC_TIMES) AS CNT "
            szSql &= "FROM "
            szSql &= "( "
            szSql &= "SELECT PROC_TIMES "
            szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
            szSql &= "WHERE LOT_NO = '" & szLotNo & "' "
            szSql &= "AND KOUTEI_CD = '" & .Item("KOUTEI_CD") & "' "
            szSql &= "AND TYPE = '" & type & "' " 'ADD 苗 2018/1/23
            szSql &= ") A"
        End With

        Dim dtCnt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsDBNull(dtCnt.Rows(0)("CNT")) Then
            dtCnt.Rows(0)("CNT") = 0
        End If
        'UPD 苗 2018/1/23 BEGIN
        'If type.Equals(BEGIN) Then
        count = CInt(dtCnt.Rows(0)("CNT")) + 1
        'ElseIf type.Equals(COMPLETE) Then
        '    count = CInt(dtCnt.Rows(0)("CNT")) + 1
        'Else
        '    count = CInt(dtCnt.Rows(0)("CNT"))
        'End If
        'UPD 苗 2018/1/23 END

        szSql = ""
        '>>20180323 大賀 No117 ロットキャンセルの履歴保存
        If type.Equals(BEGIN) Or type.Equals(CANCEL) Then
            '<<20180323 大賀 No117 ロットキャンセルの履歴保存
            With dtHeader.Rows(0)
                Dim BeginTime = IIf(type.Equals(BEGIN), szDteBegin, .Item("BEGIN_TIME"))
                szSql &= "INSERT INTO MAT.L_SF_WORK_RSLT_HEAD(  "
                szSql &= "  LOT_NO, KOUTEI_CD, TYPE, PROC_TIMES, OPERATOR, OPT_TIME, "
                szSql &= "  EQUIP_ID, PROD_NAME, DIFF_LOT, PB_LAYOUT, SHAPE,  "
                szSql &= "  BEGIN_TIME, BEGIN_OPT,  "
                szSql &= "  INPUT_QTY, INPUTFRM_QTY, INPUTCROSS_QTY, INPUTCROSS_FRMQTY,"
                szSql &= "  COMPLETE_QTY, DEFECT_QTY, FRAME_QTY, CROSS_QTY, CROSS_FRMQTY,  "
                '>>20180302 大賀 GroupKey入力時ウェハ枚数入力
                szSql &= "  INPUT_WAFER_QTY, WAFER_QTY,  "
                '<<20180302 大賀 GroupKey入力時ウェハ枚数入力
                szSql &= "  IS_CHECKED, Q_FLAG, UPDATE_TIME "
                szSql &= ")  "
                szSql &= "VALUES (  "
                szSql &= "  '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', "
                szSql &= "  '{6}', '{7}', '{8}', '{9}', '{10}', "
                szSql &= "  '{11}', '{12}', "
                szSql &= "  '{13}', '{14}', '{15}', "
                szSql &= "  '{16}', '{17}', '{18}', '{19}', "
                szSql &= "  '{20}', '{21}', '{22}', '{23}' , '{24}', '{25}' , '{26}'"
                szSql &= ")  "

                szSql = String.Format(szSql, szLotNo, .Item("KOUTEI_CD"), type, count, .Item("OPERATOR"), szDteBegin,
                                .Item("EQUIP_ID"), .Item("PROD_NAME"), .Item("DIFF_LOT"), .Item("PB_LAYOUT"), .Item("SHAPE"),
                                BeginTime, .Item("BEGIN_OPT"),
                                .Item("INPUT_QTY"), .Item("INPUTFRM_QTY"), .Item("INPUTCROSS_QTY"), .Item("INPUTCROSS_FRMQTY"),
                               IIf(.Item("COMPLETE_QTY") = "0", CInt(.Item("INPUT_QTY")) - CInt(.Item("DEFECT_QTY")), .Item("COMPLETE_QTY")), .Item("DEFECT_QTY"), .Item("FRAME_QTY"), .Item("CROSS_QTY"), .Item("CROSS_FRMQTY"),
                                .Item("INPUT_WAFER_QTY"), .Item("WAFER_QTY"),
                                .Item("IS_CHECKED"), IIf(.Item("Q_FLAG").ToString.ToUpper = "TRUE", 1, 0), szDteBegin) 'UPD MIAO 2018/10/31
            End With

        Else
            With dtHeader.Rows(0)
                szSql &= "INSERT INTO MAT.L_SF_WORK_RSLT_HEAD(  "
                szSql &= "  LOT_NO, KOUTEI_CD, type, PROC_TIMES, OPERATOR, OPT_TIME, "
                szSql &= "  EQUIP_ID, PROD_NAME, DIFF_LOT, PB_LAYOUT, SHAPE, "
                szSql &= "  BEGIN_TIME, BEGIN_OPT, "
                szSql &= "  INPUT_QTY, INPUTFRM_QTY, INPUTCROSS_QTY, INPUTCROSS_FRMQTY, "
                szSql &= "  COMPLETE_TIME, COMPLETE_OPT, "
                szSql &= "  COMPLETE_QTY, DEFECT_QTY, FRAME_QTY, CROSS_QTY, CROSS_FRMQTY, "
                '>>20180302 大賀 GroupKey入力時ウェハ枚数入力
                szSql &= "  INPUT_WAFER_QTY, WAFER_QTY, "
                '<<20180302 大賀 GroupKey入力時ウェハ枚数入力
                szSql &= "  IS_CHECKED, Q_FLAG, UPDATE_TIME "
                szSql &= ")  "
                szSql &= "VALUES (  "
                szSql &= "  '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', "
                szSql &= "  '{6}', '{7}', '{8}', '{9}', '{10}', "
                szSql &= "  '{11}', '{12}', "
                szSql &= "  '{13}', '{14}', '{15}', "
                szSql &= "  '{16}', '{17}', "
                szSql &= "  '{18}', '{19}', '{20}', '{21}', "
                szSql &= "  '{22}', '{23}' , '{24}' , '{25}' , '{26}' , '{27}' , '{28}'"
                szSql &= ")  "

                szSql = String.Format(szSql, szLotNo, .Item("KOUTEI_CD"), type, count, .Item("OPERATOR"), szDteBegin,
                                .Item("EQUIP_ID"), .Item("PROD_NAME"), .Item("DIFF_LOT"), .Item("PB_LAYOUT"), .Item("SHAPE"),
                                .Item("BEGIN_TIME"), .Item("BEGIN_OPT"),
                                .Item("INPUT_QTY"), .Item("INPUTFRM_QTY"), .Item("INPUTCROSS_QTY"), .Item("INPUTCROSS_FRMQTY"),
                                szDteBegin, .Item("COMPLETE_OPT"),
                               IIf(.Item("COMPLETE_QTY") = "0", CInt(.Item("INPUT_QTY")) - CInt(.Item("DEFECT_QTY")), .Item("COMPLETE_QTY")), .Item("DEFECT_QTY"), .Item("FRAME_QTY"), .Item("CROSS_QTY"), .Item("CROSS_FRMQTY"),
                                .Item("INPUT_WAFER_QTY"), .Item("WAFER_QTY"),
                                .Item("IS_CHECKED"), IIf(.Item("Q_FLAG").ToString.ToUpper = "TRUE", 1, 0), szDteBegin) 'UPD MIAO 2018/10/31
            End With
        End If

        Dim cnt As Integer = DBacs.ExecuteUpdateSql(szSql, -1)
        If cnt < 0 Then
            Return DateTime.MinValue
        Else
            Return DateTime.MaxValue
        End If
    End Function

    Private Function UpdateHeader(ByVal dtHeader As DataTable, ByVal status As frmStartCompleteBase.ProcessStatus,
                                  ByVal szLotNo As String, ByVal szEquipID As String, ByVal dtBegin As Object) As Integer
        Dim szSql As String = ""
        With dtHeader.Rows(0)
            szSql &= "UPDATE MAT.L_EQUIP_MAT_HEADER "
            szSql &= "SET "
            szSql &= "  PROD_NAME ='" & .Item("PROD_NAME") & "', "
            szSql &= "  DIFF_LOT = '" & .Item("DIFF_LOT") & "', "
            szSql &= "  PB_LAYOUT = '" & .Item("PB_LAYOUT") & "', "
            szSql &= "  SHAPE = '" & .Item("SHAPE") & "', "
            Select Case status
                Case ProcessStatus.ManufComplete
                    szSql &= "  STATUS ='" & .Item("STATUS") & "', "
                    szSql &= "  COMPLETE_TIME = '" & .Item("COMPLETE_TIME") & "', "
                    szSql &= "  COMPLETE_OPT = '" & .Item("COMPLETE_OPT") & "', "
                Case ProcessStatus.TotalComplete
                    szSql &= "  STATUS ='" & .Item("STATUS") & "', "
                    szSql &= "  TOTAL_TIME = '" & .Item("TOTAL_TIME") & "', "
                    szSql &= "  TOTAL_OPT = '" & .Item("TOTAL_OPT") & "', "
                Case ProcessStatus.Canceled
                    szSql &= "  STATUS ='" & .Item("STATUS") & "', "
                Case ProcessStatus.Hold
                    szSql &= "  STATUS ='" & .Item("STATUS") & "', "
            End Select
            szSql &= "  INPUT_QTY = '" & .Item("INPUT_QTY") & "', "
            szSql &= "  INPUTFRM_QTY = '" & .Item("INPUTFRM_QTY") & "', "
            szSql &= "  INPUTCROSS_QTY = '" & .Item("INPUTCROSS_QTY") & "', "
            szSql &= "  COMPLETE_QTY = '" & .Item("COMPLETE_QTY") & "', "
            szSql &= "  DEFECT_QTY = '" & .Item("DEFECT_QTY") & "', "
            szSql &= "  FRAME_QTY = '" & .Item("FRAME_QTY") & "', "
            szSql &= "  CROSS_QTY = '" & .Item("CROSS_QTY") & "', "
            szSql &= "  IS_CHECKED = '" & .Item("IS_CHECKED") & "', "
            szSql &= "  Q_FLAG = '" & .Item("Q_FLAG") & "' "
            szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
            szSql &= "AND LOT_NO='" & szLotNo & "' "
            'szSql &= "AND KOUTEI_CD = '" & .Item("KOUTEI_CD") & "' "
            szSql &= "AND BEGIN_TIME = '" & dtBegin & "' "
        End With

        UpdateHeader = DBacs.ExecuteUpdateSql(szSql, -1)
    End Function

    '蘇州対応　2017/04/24 maruyama
    'プロセスコードからプロセス名、テーブル名、完了数を取得する
    '蘇州対応　テープUV　2017/04/13 maruyama@tmc
    Public Function GetEquipMatTapyUV_Limittime(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String, ByVal Status As TagProcessStatus) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT "
        szSql &= "case when complete_time > total_time then complete_time "
        szSql &= "else total_time end as LIMIT_TIME "
        szSql &= "from mat.l_equip_mat_dicing "
        szSql &= "where lot_no = "
        szSql &= String.Format("'{0}'", szLotNo)
        szSql &= " order by "
        szSql &= "case when complete_time > total_time then complete_time "
        szSql &= "else total_time end "
        szSql &= "desc "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatTapyUV_Limittime = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatTapyUV_Limittime = dt
        End If
    End Function

    '蘇州対応 2017/04/24 maruyama@tmc
    'レーザーダイシング
    Public Function GetEquipMatLaserDicing(ByVal szOLDEquipID As String, ByVal szEquipID As String, ByVal szLotNo As String,
                                      ByVal Status As TagProcessStatus, ByVal Proc_Table As String, ByVal Pre_Proc_TABLE As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT SV2.CROSS_QTY, "
        szSql &= "   SV2.LASER_DICING_SELF_CHECK, "
        szSql &= "   SAV.WAFER_COMPLETE AS WAFER_INPUT, SV2.WAFER_COMPLETE, "
        szSql &= "   SV2.LASER_DICING_WAFER_D, SV2.LASER_DICING_WAFER_T ,"
        szSql &= "   SV2.LASER_DICING_RECIP_CHECK,"
        szSql &= "   SAV.CASE_NO AS PRE_CASE_NO ,"
        szSql &= "   EXTRACT(epoch FROM current_timestamp - "
        szSql &= "   CASE WHEN SAV.COMPLETE_TIME > SAV.TOTAL_TIME THEN SAV.COMPLETE_TIME "
        szSql &= "   ELSE SAV.TOTAL_TIME END )/3600 AS DEMMY_TIME ,"
        szSql &= "   SV2.LASER_DICING_DUMMY_JYOKEN , SV2.LASER_DICING_DUMMY_CHECK"

        szSql &= SqlCondLastTime(szOLDEquipID, szEquipID, szLotNo, Status, Proc_Table, Pre_Proc_TABLE)

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szEquipID, szLotNo)
        If IsNothing(dt) Then
            GetEquipMatLaserDicing = New DataTable
        Else
            SolveNull(dt)
            GetEquipMatLaserDicing = dt
        End If
    End Function

    Public Function SaveLaserDicing(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szLaserDicing() As String, ByVal szWafer As String) As Integer

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_LASER_DICING "
        szSql &= "SET "
        szSql &= "  LASER_DICING_SELF_CHECK_NUM ='" & szLaserDicing(0) & "', "
        szSql &= "  LASER_DICING_HOGPMAX ='" & szLaserDicing(1) & "', "
        szSql &= "  LASER_DICING_LASERKERF ='" & szLaserDicing(2) & "', "
        szSql &= "  WAFER_COMPLETE ='" & szWafer & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function

    ' 蘇州対応 2017/05/10 T.Yutaro Add Start
    Public Function UpdateEquipMatMoldQC(ByVal szOldEquipID As String, ByVal szEquipID As String,
                                       ByVal szLotNo As String, ByVal szSysEquipID As String, ByVal szEquipNo As String,
                                       ByVal szProcCD As String, ByVal dtEquipMat As DataTable,
                                       ByRef szBeginTM As DateTime, ByVal szBeginOpt As String, ByVal dtHeader As DataTable) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE MAT.L_EQUIP_MAT_MOLDQC "
        szSql &= "SET "
        'szSql &= "  BEGIN_TIME ='" & szBeginTM & "', "
        'szSql &= "  BEGIN_OPT ='" & szBeginOpt & "', "
        szSql &= "  IS_DONE = TRUE "
        szSql &= "WHERE EQUIP_ID='" & szOldEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_CONDITION=FALSE "

        DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)

        'ヘッダー情報を保存
        Dim dte As DateTime = SaveHeader(dtHeader, 0, szLotNo, szEquipID, "", szBeginTM)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        Else
            szBeginTM = dte
        End If

        Dim cnt As Integer

        With dtEquipMat.Rows(1)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MOLDQC( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, IS_CONDITION, "
            szSql &= "  CONS_RACK_NO, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', TRUE, " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("CONS_RACK_NO"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMoldQC = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        With dtEquipMat.Rows(0)
            szSql = "INSERT INTO MAT.L_EQUIP_MAT_MOLDQC( "
            szSql &= "  SYS_EQUIP_ID, EQUIP_ID, EQUIP_NO, LOT_NO, KOUTEI_CD, "
            szSql &= "  CONS_RACK_NO, "
            szSql &= "  BEGIN_TIME, BEGIN_OPT "
            szSql &= ") "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}', '{3}', '{4}', " &
                                   "'{5}', " &
                                   "'{6}', '{7}'",
                                  szSysEquipID, szEquipID, szEquipNo, szLotNo, szProcCD,
                                  .Item("CONS_RACK_NO"),
                                  dte, szBeginOpt)
            szSql &= ")"

            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            UpdateEquipMatMoldQC = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If

        End With

        DBacs.CommitTransaction()
    End Function

    Public Function SaveEquipMatMoldQC(ByVal szEquipID As String, ByVal szLotNo As String, ByVal szTable As String, ByVal htFinish As Hashtable) As Integer
        Dim szSql As String = ""
        szSql &= String.Format("UPDATE MAT.{0} ", szTable)
        szSql &= "SET "
        szSql &= "  CONS_RACK_NO ='" & htFinish("CONS_RACK_NO") & "', "
        szSql &= "  CHECK_QTY ='" & htFinish("CHECK_QTY") & "' "
        szSql &= "WHERE EQUIP_ID='" & szEquipID & "' "
        szSql &= "AND LOT_NO='" & szLotNo & "' "
        szSql &= "AND IS_DONE = FALSE "
        szSql &= "AND IS_CONDITION=FALSE "

        Return DBacs.ExecuteUpdateSql(szSql, -1, szEquipID, szLotNo)
    End Function
    ' 蘇州対応 2017/05/10 T.Yutaro Add End

    ' 蘇州対応 2017/05/23 T.Yutaro Add Start
    ' 工程明細テーブル更新処理
    Public Function SaveDetail(ByVal LotNo As String, ByVal procsCD As String, ByVal type As String,
                               ByVal procsTable As String, ByVal dtDBUpd As DataTable,
                               ByVal dtHeader As DataTable, ByVal szEquipID As String, ByVal serverTime As DateTime) As Integer
        DBacs.BeginTransaction()
        Dim szSql As String = ""
        Dim dte As DateTime
        Dim count As Integer
        Dim cnt As Integer 'ADD MIAO 2018/10/18
        Dim m_cData As New clsDbCondData
        'ヘッダー情報を保存
        serverTime = m_cData.GetServerTime()
        dte = SaveHeader(dtHeader, count, LotNo, szEquipID, type, serverTime)

        If dte = DateTime.MinValue Then
            DBacs.RollbackTransaction()
            Return -10
        End If

        szSql = ""
        For i = 0 To dtDBUpd.Rows.Count - 1
            With dtDBUpd.Rows(i)
                szSql = ""

                szSql &= String.Format("INSERT INTO MAT.{0}( ", procsTable)
                szSql &= "LOT_NO, KOUTEI_CD, TYPE, PROC_TIMES, "
                szSql &= "MNF_CND_TAG, MNF_CND_TAG_FLG, SEQ, MNF_CONDITION, ACTUAL_MODEL, "
                szSql &= "MANAGEMENT_NO, MATERIAL_LOT, LIMIT_TIME, UPDATE_TIME "
                szSql &= ") "
                szSql &= "VALUES ( "
                szSql &= String.Format(" '{0}', '{1}', '{2}', {3}, " &
                                       " '{4}', '{5}', {6}, '{7}', '{8}', " &
                                       " '{9}', '{10}', '{11}', '{12}'",
                                       LotNo, procsCD, type, count,
                                      .Item("MNF_CND_TAG"), .Item("MNF_CND_TAG_FLG"), .Item("SEQ"), .Item("MNF_CONDITION"), .Item("ACTUAL_MODEL"),
                                      .Item("MANAGEMENT_NO"), .Item("MATERIAL_LOT"), .Item("LIMIT_TIME"), serverTime)
                szSql &= " );" 'UPD MIAO 2018/10/18
            End With
            'ADD MIAO 2018/10/18 Begin
            cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        Next

        If Not szSql = "" Then
            'DEL MIAO 2018/10/18 Begin
            'Dim cnt As Integer
            'cnt = DBacs.ExecuteUpdateSql(szSql, -1)
            'DEL MIAO 2018/10/18 End
            SaveDetail = cnt
            If cnt < 0 Then
                DBacs.RollbackTransaction()
                Exit Function
            End If
        Else
            SaveDetail = 0
        End If

        DBacs.CommitTransaction()
    End Function

    '>>20171202 兪
    ' 工程明細テーブル更新処理
    Public Function UpdateRack(ByVal LotNo As String, ByVal procsCD As String, ByVal type As String,
                               ByVal procsTable As String, ByVal dtDBUpd As DataTable,
                               ByVal szEquipID As String) As Integer
        Dim szSql As String = ""
        Dim count As Integer

        szSql = ""
        szSql &= "SELECT MAX(PROC_TIMES) AS CNT "
        szSql &= "FROM "
        szSql &= "( "
        szSql &= "SELECT PROC_TIMES "
        szSql &= "FROM MAT." & procsTable & " "
        szSql &= "WHERE LOT_NO = '" & LotNo & "' "
        szSql &= "AND KOUTEI_CD = '" & procsCD & "' "
        szSql &= "AND TYPE = '" & type & "' "
        szSql &= ") A"

        Dim dtCnt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsDBNull(dtCnt.Rows(0)("CNT")) Then
            dtCnt.Rows(0)("CNT") = 0
        End If

        If type.Equals(BEGIN) Then
            count = CInt(dtCnt.Rows(0)("CNT")) + 1
        ElseIf type.Equals(COMPLETE) Then
            count = CInt(dtCnt.Rows(0)("CNT"))
        Else
            count = CInt(dtCnt.Rows(0)("CNT"))
        End If

        Dim cnt As Integer
        szSql = ""
        DBacs.BeginTransaction()
        For i = 0 To dtDBUpd.Rows.Count - 1
            Dim szSqlInsert As String = ""
            Dim szSqlUpdate As String = ""
            Dim szSqlExec As String = ""
            szSqlInsert &= "INSERT INTO MAT.{0}( "
            szSqlInsert &= "LOT_NO, KOUTEI_CD, TYPE, PROC_TIMES, "
            szSqlInsert &= "MNF_CND_TAG, MNF_CND_TAG_FLG, SEQ, MNF_CONDITION, ACTUAL_MODEL, "
            szSqlInsert &= "MANAGEMENT_NO, MATERIAL_LOT, LIMIT_TIME "
            szSqlInsert &= ") "
            szSqlInsert &= "VALUES ( "
            szSqlInsert &= " '{1}', '{2}', '{3}', {4}, "
            szSqlInsert &= " '{5}', '{6}', {7}, '{8}', '{9}', "
            szSqlInsert &= " '{10}', '{11}', '{12}');"

            szSqlUpdate &= "UPDATE MAT.{0} SET "
            szSqlUpdate &= "  MNF_CND_TAG_FLG = '{6}', "
            szSqlUpdate &= "  MNF_CONDITION = '{8}', "
            szSqlUpdate &= "  ACTUAL_MODEL = '{9}', "
            szSqlUpdate &= "  MANAGEMENT_NO = '{10}', "
            szSqlUpdate &= "  MATERIAL_LOT = '{11}', "
            szSqlUpdate &= "  LIMIT_TIME = '{12}' "
            szSqlUpdate &= "WHERE "
            szSqlUpdate &= "     LOT_NO = '{1}' "
            szSqlUpdate &= " AND KOUTEI_CD = '{2}' "
            szSqlUpdate &= " AND TYPE = '{3}' "
            szSqlUpdate &= " AND PROC_TIMES = '{4}' "
            szSqlUpdate &= " AND MNF_CND_TAG = '{5}' "
            szSqlUpdate &= " AND SEQ = {7} ;"
            With dtDBUpd.Rows(i)
                szSqlExec = String.Format(szSqlUpdate, procsTable, LotNo, procsCD, type, count,
                            .Item("MNF_CND_TAG"), "0", .Item("SEQ"), "", .Item("ACTUAL_MODEL"),
                            "", "", "")
                If Not szSqlExec = "" Then
                    cnt = DBacs.ExecuteUpdateSql(szSqlExec, -1)
                    If cnt = 0 Then
                        szSqlExec = String.Format(szSqlInsert, procsTable, LotNo, procsCD, type, count,
                            .Item("MNF_CND_TAG"), "0", .Item("SEQ"), "", .Item("ACTUAL_MODEL"),
                            "", "", "")
                        cnt = DBacs.ExecuteUpdateSql(szSqlExec, -1)
                    End If
                End If
                If cnt < 0 Then
                    DBacs.RollbackTransaction()
                    Return cnt
                End If
            End With
        Next

        DBacs.CommitTransaction()

        Return cnt
    End Function
    '<<20171202 兪

    ' 工程明細テーブル取得処理
    Public Function GetDetailResult(ByVal LotNo As String, ByVal procsCD As String, ByVal type As String, ByVal procsTable As String) As DataTable
        Dim szSql As String = ""
        If procsTable.ToUpper.Equals("MAT.L_SF_WORK_RSLT_A42") Then Return New DataTable
        szSql &= "SELECT "
        szSql &= "A.TYPE, A.MNF_CND_TAG, A.MNF_CND_TAG_FLG, A.SEQ, A.PROC_TIMES, A.MNF_CONDITION, A.ACTUAL_MODEL, "
        szSql &= "A.MANAGEMENT_NO, A.MATERIAL_LOT, A.LIMIT_TIME "
        szSql &= String.Format("FROM MAT.{0} AS A ", procsTable)
        szSql &= "WHERE LOT_NO = '" & LotNo & "' "
        szSql &= "AND KOUTEI_CD = '" & procsCD & "' "
        szSql &= "AND TYPE = '" & type & "' "
        szSql &= "AND PROC_TIMES = ("
        szSql &= "  SELECT MAX(PROC_TIMES) "
        szSql &= String.Format("FROM MAT.{0} AS B ", procsTable)
        szSql &= "  WHERE A.LOT_NO = B.LOT_NO "
        szSql &= "  AND A.KOUTEI_CD = B.KOUTEI_CD "
        szSql &= "  AND A.TYPE = B.TYPE "
        szSql &= ")"
        If procsTable.ToUpper.Equals("L_SF_WORK_RSLT_A42") Then Return New DataTable

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, LotNo)
        If IsNothing(dt) Then
            GetDetailResult = New DataTable
        Else
            GetDetailResult = dt
        End If
    End Function

    '>> 2018/2/26 佐川 仕掛情報保存先変更
    ' 工程明細テーブル取得処理
    Public Function GetDetailResultDbBake(ByVal LotNo As String, ByVal procsCD As String) As DataTable
        Dim szSql As String = ""

        szSql &= " SELECT EQUIP_NO, SEQ_NO, LOT_NO "
        szSql &= " FROM PER.T_WORKING_LOT "
        szSql &= " WHERE EQUIP_NO = ? AND PROC_CD = ? "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, LotNo, procsCD)
        If IsNothing(dt) Then
            GetDetailResultDbBake = New DataTable
        Else
            GetDetailResultDbBake = dt
        End If
    End Function
    '<< 2018/2/26 佐川 仕掛情報保存先変更

    Public Function GetPreDetailData(ByVal LotNo As String, ByVal type As String, ByVal preProcsTable As String) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT "
        szSql &= "MNF_CND_TAG, TYPE, PROC_TIMES, SEQ, MNF_CONDITION, ACTUAL_MODEL, "
        szSql &= "MANAGEMENT_NO, MATERIAL_LOT, LIMIT_TIME "
        szSql &= String.Format("FROM MAT.{0} AS A ", preProcsTable)
        szSql &= "WHERE LOT_NO = '" & LotNo & "' "
            szSql &= "AND TYPE = '" & type & "' "
        szSql &= "AND PROC_TIMES = ("
        szSql &= "  SELECT MAX(PROC_TIMES) "
        szSql &= String.Format("FROM MAT.{0} AS B ", preProcsTable)
        szSql &= "  WHERE A.LOT_NO = B.LOT_NO "
        szSql &= "  AND A.KOUTEI_CD = B.KOUTEI_CD "
        szSql &= "  AND A.TYPE = B.TYPE "
        szSql &= ")"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, LotNo)
        If IsNothing(dt) Then
            GetPreDetailData = New DataTable
        Else
            GetPreDetailData = dt
        End If
    End Function

    ' 製造条件取得（l_jyokendata）
    Public Function GetKoteiData(ByVal LotNo As String, ByVal procCD As String, ByVal SelectLotNo As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT KOMOKUDATA AS PROC, '' AS PROC_CD , '' AS PROC_TABLE , '' AS PROC_NAME, '' AS QTY "
        szSql &= "FROM PER.L_JYOKENDATA "
        szSql &= "WHERE ( "
        szSql &= " SELECT TO_NUMBER(KOMOKUNAME,'99') "
        szSql &= " FROM PER.L_JYOKENDATA "
        szSql &= " WHERE KOMOKUDATA = '" & procCD & "' "
        szSql &= " AND KLOTNO = '" & LotNo & "' "
        szSql &= " AND KOTEI = 'PROCESS_INFO' "
        szSql &= " ) - 2 <= TO_NUMBER(KOMOKUNAME, '99') "
        szSql &= "AND ( "
        szSql &= " SELECT TO_NUMBER(KOMOKUNAME,'99') "
        szSql &= " FROM PER.L_JYOKENDATA "
        szSql &= " WHERE KOMOKUDATA = '" & procCD & "' "
        szSql &= " AND KLOTNO = '" & LotNo & "' "
        szSql &= " AND KOTEI = 'PROCESS_INFO' "
        szSql &= " ) + 4 >= TO_NUMBER(KOMOKUNAME, '99') "
        szSql &= "AND KLOTNO = '" & LotNo & "' "
        szSql &= "AND KOTEI = 'PROCESS_INFO' "
        szSql &= "ORDER BY TO_NUMBER(KOMOKUNAME, '99')"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, LotNo)
        If Not IsNothing(dt) AndAlso dt.Rows.Count > 0 Then

            With dt
                For Each dr As DataRow In .Rows
                    szSql = "SELECT PROC_CD , PROC_TABLE, PROC_NAME FROM PER.T_PROC_CD "
                    szSql &= "WHERE PROC_CD ='{0}' "

                    Dim szProcCD As String = dr("PROC").ToString


                    If Not String.IsNullOrEmpty(szProcCD) Then
                        Dim dtComp As DataTable = DBacs.ExecuteSql(String.Format(szSql, szProcCD))
                        If Not IsNothing(dtComp) AndAlso dtComp.Rows.Count > 0 AndAlso Not IsDBNull(dtComp.Rows(0)(0)) Then
                            dr("PROC_CD") = dtComp.Rows(0)(0)
                            dr("PROC_TABLE") = dtComp.Rows(0)(1)
                            dr("PROC_NAME") = dtComp.Rows(0)(2)
                        Else
                            dr("PROC_CD") = String.Empty
                            dr("PROC_TABLE") = String.Empty
                            dr("PROC_NAME") = String.Empty
                        End If
                    End If

                    szSql = "SELECT COMPLETE_QTY FROM MAT.L_SF_WORK_RSLT_HEAD "
                    szSql &= "WHERE LOT_NO='" & SelectLotNo & "' "
                    szSql &= "AND KOUTEI_CD ='{0}' "
                    szSql &= "AND TYPE = '" & TOTAL & "' "
                    szSql &= "AND ROWNUM <= 1 " 'ADD MIAO 2018/10/17
                    szSql &= "ORDER BY PROC_TIMES DESC "
                    'szSql &= "LIMIT 1 "'DEL MIAO 2018/10/17


                    If Not String.IsNullOrEmpty(dr("PROC_CD")) Then
                        Dim dtComp As DataTable = DBacs.ExecuteSql(String.Format(szSql, dr("PROC_CD")))
                        If Not IsNothing(dtComp) AndAlso dtComp.Rows.Count > 0 AndAlso Not IsDBNull(dtComp.Rows(0)(0)) Then
                            dr("QTY") = dtComp.Rows(0)(0)
                        Else
                            dr("QTY") = String.Empty
                        End If
                    End If
                Next

            End With
            GetKoteiData = dt
        Else
            GetKoteiData = dt
        End If

    End Function

    Public Function GetTitle(ByVal procCD As String) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT "
        '>>20171202 兪
        szSql &= "PROC_CD, PROC_NAME, PROC_TABLE, PREPROC_LOTTYPE, AUTO_X "
        szSql &= " , FRAMEID_COMP ,InputLotType " 'ADD 苗 2018/1/26  フレームID対応 2018/2/1 InputLotType取得
        '<<20171202 兪
        szSql &= " , X_INPUT_FLAG " 'ADD 安部 2018/2/4 ×印入力制御追加
        szSql &= " , inspection_qty_type " 'ADD 安部 2018/2/19 検査数量タイプ追加
        szSql &= " , completetype " 'ADD 安部 2018/2/19 completetype追加
        '>>20180302 大賀 GroupKey入力時ウェハ枚数入力
        szSql &= " , wf_write_flag "
        szSql &= " , wf_read_flag "
        '<<20180302 大賀 GroupKey入力時ウェハ枚数入力
        szSql &= " ,RACK_FLOW_FLAG "
        szSql &= "FROM PER.T_PROC_CD "
        szSql &= "WHERE PROC_CD = '" & procCD & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            GetTitle = New DataTable
        Else
            GetTitle = dt
        End If
    End Function

    Public Function GetResultHead(ByVal szLotNo As String, ByVal type As String, ByVal szProcCD As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT "
        If type.Equals(BEGIN) Then
            szSql &= "TO_CHAR(BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, BEGIN_OPT, "
            szSql &= "'' AS END_TIME, '' AS END_OPT, CROSS_QTY "
            'ADD 2018/1/4 苗 BEING
            '×印枚数
            szSql &= ",CROSS_FRMQTY "
            'ADD 2018/1/4 苗 END
        ElseIf type.Equals(COMPLETE) Then
            szSql &= "TO_CHAR(BEGIN_TIME, 'YYYY/MM/DD HH24:MI:SS') AS BEGIN_TIME, BEGIN_OPT, "
            szSql &= "TO_CHAR(COMPLETE_TIME, 'YYYY/MM/DD HH24:MI:SS') AS END_TIME, COMPLETE_OPT AS END_OPT, CROSS_QTY "
            'ADD 2018/1/4 苗 BEING
            '×印枚数
            szSql &= ",CROSS_FRMQTY "
            'ADD 2018/1/4 苗 END
        End If
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD AS A "
        szSql &= "WHERE LOT_NO = '" & szLotNo & "' "
        szSql &= "AND TYPE = '" & type & "' "
        szSql &= "AND KOUTEI_CD = '" & szProcCD & "' "
        szSql &= "AND PROC_TIMES = ("
        szSql &= "  SELECT MAX(PROC_TIMES) "
        szSql &= "  FROM MAT.L_SF_WORK_RSLT_HEAD AS B "
        szSql &= "  WHERE A.LOT_NO = B.LOT_NO "
        szSql &= "  AND A.KOUTEI_CD = B.KOUTEI_CD "
        szSql &= "  AND A.TYPE = B.TYPE "
        szSql &= ")"

        GetResultHead = DBacs.ExecuteSql(szSql, -1)
    End Function

    Public Function GetPreHeader(ByVal szLotNo As String, ByVal szProcCD As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT DIFF_LOT, PROD_NAME, SHAPE, COMPLETE_QTY, FRAME_QTY "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD AS A "
        szSql &= "WHERE LOT_NO = '" & szLotNo & "' "
        szSql &= "AND TYPE = '" & TOTAL & "' "
        szSql &= "AND KOUTEI_CD = '" & szProcCD & "' "
        szSql &= "AND PROC_TIMES = ("
        szSql &= "  SELECT MAX(PROC_TIMES) "
        szSql &= "  FROM MAT.L_SF_WORK_RSLT_HEAD AS B "
        szSql &= "  WHERE A.LOT_NO = B.LOT_NO "
        szSql &= "  AND A.KOUTEI_CD = B.KOUTEI_CD "
        szSql &= "  AND A.TYPE = B.TYPE "
        szSql &= ")"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        If IsNothing(dt) Then
            GetPreHeader = New DataTable
        Else
            GetPreHeader = dt
        End If
    End Function
    ' 蘇州対応 2017/05/23 T.Yutaro Add End
    '蘇州対応　2017/05/30 maruyama
    'レーザーダイシング：（計上完成）
    Public Function getCompleteTimeFromKeijyo(ByVal szProcCD As String, ByVal szEquipID As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT COMPLETE_TIME,LOT_NO,PROC_TIMES,current_timestamp as CURRENT_TIME "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
        szSql &= "WHERE TYPE = '3' AND "
        szSql &= "KOUTEI_CD = '" & szProcCD & "' AND "
        szSql &= "EQUIP_ID = '" & szEquipID & "' AND "
        szSql &= "COMPLETE_TIME Is Not NULL "
        szSql &= "ORDER BY COMPLETE_TIME DESC "
        szSql &= "LIMIT 1"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        getCompleteTimeFromKeijyo = dt

    End Function
    'レーザーダイシング：（製造完成）
    Public Function getCompleteTimeFromSeizo(ByVal szLotNo As String, ByVal szProcCD As String, ByVal szTimes As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT COMPLETE_TIME "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
        szSql &= "WHERE TYPE = '2' AND "
        szSql &= "KOUTEI_CD = '" & szProcCD & "' AND "
        szSql &= "LOT_NO = '" & szLotNo & "' AND "
        szSql &= "PROC_TIMES = '" & szTimes & "' AND "
        szSql &= "COMPLETE_TIME Is Not NULL "
        szSql &= "ORDER BY COMPLETE_TIME DESC "
        szSql &= "LIMIT 1"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        getCompleteTimeFromSeizo = dt

    End Function
    'レーザーダイシング：（check）
    Public Function getCompleteTimeCheckForLD(ByVal szProcCD As String, ByVal szEquipID As String, ByVal szHour As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT  LOT_NO, KOUTEI_CD, PROC_TIMES, MIN(COMPLETE_TIME) AS MIN_COMP "
        szSql &= " FROM  MAT.L_SF_WORK_RSLT_HEAD"
        szSql &= " WHERE TYPE IN ('2', '3') "
        szSql &= "   AND EQUIP_ID = '" & szEquipID & "' "
        szSql &= " GROUP BY  LOT_NO, KOUTEI_CD, PROC_TIMES "
        szSql &= " HAVING  MIN(COMPLETE_TIME) >= CURRENT_TIMESTAMP - INTERVAL '" & szHour & " HOUR';  "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        getCompleteTimeCheckForLD = dt

    End Function

    '蘇州対応　2017/06/27 gotou
    ' 製造完成データ有無を取得
    Public Function getBakeManufCompData(ByVal szLotNo As String, ByVal szProcCD As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT MAX(PROC_TIMES) AS proc_times "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_" & szProcCD & " "
        szSql &= "WHERE LOT_NO ='" & szLotNo & "' "
        szSql &= "AND TYPE ='1'"
        Dim proc As DataTable = DBacs.ExecuteSql(szSql, -1)

        Dim szProcTimes As Integer = 1
        If Integer.Parse(proc.Rows(0)("proc_times")) > 0 Then
            szProcTimes = proc.Rows(0)("proc_times")
        End If

        szSql = ""

        szSql &= "Select COUNT(*) COUNT " 'UPD MIAO 2018/11/05
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
        szSql &= "WHERE TYPE = '2' AND "
        szSql &= "PROC_TIMES = '" & szProcTimes & "' AND "
        szSql &= "KOUTEI_CD = '" & szProcCD & "' AND "
        szSql &= "LOT_NO = '" & szLotNo & "' AND "
        szSql &= "COMPLETE_TIME Is Not NULL "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        getBakeManufCompData = dt

    End Function

    'ヘッダー情報から完了時間取得
    Public Function getMaxComplete_Time(ByVal szLotNo As String, ByVal szProcCD As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT MAX(COMPLETE_TIME) AS COMPLETE_TIME "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
        szSql &= "WHERE KOUTEI_CD = '" & szProcCD & "' AND "
        szSql &= "LOT_NO = '" & szLotNo & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsDBNull(dt.Rows(0)(0)) Then
            getMaxComplete_Time = Nothing
        Else
            getMaxComplete_Time = dt
        End If

    End Function

    'ヘッダー情報から品名を取得
    Public Function getPrond_Name(ByVal szEqpCd As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT A.PROD_NAME AS PROD_NAME "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD AS A "
        szSql &= "INNER JOIN KAD.T_EQUIP_REG AS B "
        szSql &= "ON A.KOUTEI_CD = B.KOUTEI_CODE AND "
        szSql &= "B.EQUIP_ID = '" & szEqpCd & "' "
        szSql &= "WHERE A.COMPLETE_TIME IS NOT NULL "
        szSql &= "AND A.EQUIP_ID = '" & szEqpCd & "' "
        szSql &= "ORDER BY A.COMPLETE_TIME DESC"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getPrond_Name = New DataTable
        Else
            getPrond_Name = dt
        End If
    End Function

    '拡散ロットNoをキーに設備、工程を更新する。
    Public Function UpdateL_LotDataFromDiffLotNo(ByVal szDifLotNo As String, ByVal szEquipID As String, ByVal szProcsCD As String)
        DBacs.BeginTransaction()

        Dim szSql As String = ""

        szSql &= "UPDATE PER.L_TAG_LOTDATA "
        szSql &= "SET "
        szSql &= "  EQUIPNO      ='" & szEquipID & "', "
        szSql &= "  KOUTEI_CODE      ='" & szProcsCD & "' "
        szSql &= " WHERE WAFER_LOTNO ='" & szDifLotNo & "' "

        Dim cnt As Integer
        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        UpdateL_LotDataFromDiffLotNo = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function UpdateL_LotData_Kotei(ByVal operation As String, ByVal lotNo As String) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE PER.L_TAG_LOTDATA "
        szSql &= "SET "
        szSql &= "  KOUTEI_CODE      ='" & operation & "' "
        szSql &= "WHERE LOT_NO  ='" & lotNo & "' "

        Dim cnt As Integer
        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        UpdateL_LotData_Kotei = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function UpdateL_LotData_Status(ByVal status As Integer, ByVal lotNo As String) As Integer
        DBacs.BeginTransaction()

        Dim szSql As String = ""
        szSql &= "UPDATE PER.L_TAG_LOTDATA "
        szSql &= "SET "
        szSql &= "  STATUS      =" & status & ", "
        szSql &= "  EQUIPNO      ='' "
        szSql &= "WHERE LOT_NO  ='" & lotNo & "' "

        Dim cnt As Integer
        cnt = DBacs.ExecuteUpdateSql(szSql, -1)
        UpdateL_LotData_Status = cnt
        If cnt < 0 Then
            DBacs.RollbackTransaction()
            Exit Function
        End If

        DBacs.CommitTransaction()
    End Function

    Public Function GetDetailDataByProcCd(ByVal LotNo As String, ByVal type As String, ByVal preProcsTable As String, ByVal ProcCode As String) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT "
        szSql &= "MNF_CND_TAG, TYPE, PROC_TIMES, SEQ, MNF_CONDITION, ACTUAL_MODEL, "
        szSql &= "MANAGEMENT_NO, MATERIAL_LOT, LIMIT_TIME "
        szSql &= String.Format("FROM MAT.{0} AS A ", preProcsTable)
        szSql &= "WHERE LOT_NO = '" & LotNo & "' "
        szSql &= "AND TYPE = '" & type & "' "
        szSql &= "AND KOUTEI_CD = '" & ProcCode & "' "
        szSql &= "AND PROC_TIMES = ("
        szSql &= "  SELECT MAX(PROC_TIMES) "
        szSql &= String.Format("FROM MAT.{0} AS B ", preProcsTable)
        szSql &= "  WHERE A.LOT_NO = B.LOT_NO "
        szSql &= "  AND A.KOUTEI_CD = B.KOUTEI_CD "
        szSql &= "  AND A.TYPE = B.TYPE "
        szSql &= ")"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, LotNo)
        If IsNothing(dt) Then
            GetDetailDataByProcCd = New DataTable
        Else
            GetDetailDataByProcCd = dt
        End If
    End Function

    ' 工程明細テーブル更新処理
    Public Function SaveScrean(ByVal LotNo As String, ByVal procsCD As String, ByVal type As String,
                               ByVal procsTable As String, ByVal dtLot As DataTable) As Integer
        DBacs.BeginTransaction()
        Dim szSqlInsert As String = ""
        Dim szSqlUpdate As String = ""
        Dim szSqlExec As String = ""
        SaveScrean = 1
        szSqlInsert &= "INSERT INTO MAT.{0}( "
        szSqlInsert &= "LOT_NO, KOUTEI_CD, TYPE, PROC_TIMES, "
        szSqlInsert &= "MNF_CND_TAG, MNF_CND_TAG_FLG, SEQ, MNF_CONDITION, ACTUAL_MODEL, "
        szSqlInsert &= "MANAGEMENT_NO, MATERIAL_LOT, LIMIT_TIME, UPDATE_TIME "
        szSqlInsert &= ") "
        szSqlInsert &= "VALUES ( "
        szSqlInsert &= " '{1}', '{2}', '{3}', {4}, "
        szSqlInsert &= " '{5}', '{6}', {7}, '{8}', '{9}', "
        szSqlInsert &= " '{10}', '{11}', '{12}', NOW());"

        szSqlUpdate &= "UPDATE MAT.{0} SET "
        szSqlUpdate &= "  MNF_CND_TAG_FLG = '{6}', "
        szSqlUpdate &= "  MNF_CONDITION = '{8}', "
        szSqlUpdate &= "  ACTUAL_MODEL = '{9}', "
        szSqlUpdate &= "  MANAGEMENT_NO = '{10}', "
        szSqlUpdate &= "  MATERIAL_LOT = '{11}', "
        szSqlUpdate &= "  LIMIT_TIME = '{12}', "
        szSqlUpdate &= "  UPDATE_TIME = NOW() "
        szSqlUpdate &= "WHERE "
        szSqlUpdate &= "     LOT_NO = '{1}' "
        szSqlUpdate &= " AND KOUTEI_CD = '{2}' "
        szSqlUpdate &= " AND TYPE = '{3}' "
        szSqlUpdate &= " AND PROC_TIMES = '{4}' "
        szSqlUpdate &= " AND MNF_CND_TAG = '{5}' "
        szSqlUpdate &= " AND SEQ = {7} ;"
        For i = 0 To dtLot.Rows.Count - 1
            With dtLot.Rows(i)
                szSqlExec = String.Format(szSqlUpdate, procsTable, LotNo, procsCD, type, "0",
                            .Item("MNF_CND_TAG"), .Item("MNF_CND_TAG_FLG"), .Item("SEQ"), .Item("MNF_CONDITION"), .Item("ACTUAL_MODEL"),
                            .Item("MANAGEMENT_NO"), .Item("MATERIAL_LOT"), .Item("LIMIT_TIME"))
                If Not szSqlExec = "" Then
                    Dim cnt As Integer
                    cnt = DBacs.ExecuteUpdateSql(szSqlExec, -1)
                    If cnt <= 0 Then
                        szSqlExec = String.Format(szSqlInsert, procsTable, LotNo, procsCD, type, "0",
                            .Item("MNF_CND_TAG"), .Item("MNF_CND_TAG_FLG"), .Item("SEQ"), .Item("MNF_CONDITION"), .Item("ACTUAL_MODEL"),
                            .Item("MANAGEMENT_NO"), .Item("MATERIAL_LOT"), .Item("LIMIT_TIME"))
                        cnt = DBacs.ExecuteUpdateSql(szSqlExec, -1)
                    End If
                End If
            End With
        Next

        DBacs.CommitTransaction()
    End Function


    '>> 2018/2/26 佐川 仕掛情報保存先変更
    ' 仕掛情報保存
    Public Sub SaveScreanWorking(ByVal LotNo As String, ByVal procsCD As String, ByVal dtLot As DataTable)
        DBacs.BeginTransaction()
        Dim szSqlInsert As String = ""
        Dim szSqlExec As String = ""
        szSqlInsert &= "INSERT INTO PER.T_WORKING_LOT( "
        szSqlInsert &= "EQUIP_NO, SEQ_NO, LOT_NO, PROC_CD "
        szSqlInsert &= ") "
        szSqlInsert &= "VALUES ( "
        szSqlInsert &= " '{0}', '{1}', '{2}', '{3}');"

        For i = 0 To dtLot.Rows.Count - 1
            With dtLot.Rows(i)
                szSqlExec = String.Format(szSqlInsert, LotNo, .Item("SEQ"), .Item("LIMIT_TIME"), procsCD)
                DBacs.ExecuteSql(szSqlExec, -1)
            End With
        Next

        DBacs.CommitTransaction()
    End Sub

    '仕掛情報削除
    Public Sub saveCompScreen(ByVal LotNo As String, ByVal procsCD As String)
        Dim szSql As String = ""
        szSql &= " DELETE FROM PER.T_WORKING_LOT "
        szSql &= " WHERE EQUIP_NO = ? AND PROC_CD = ? "
        DBacs.ExecuteUpdateSql(szSql, -1, LotNo, procsCD)
    End Sub
    '>> 2018/2/26 佐川 仕掛情報保存先変更

    ' 工程明細テーブル取得処理
    Public Function GetEquipResult(ByVal LotNo As String, ByVal procsCD As String, ByVal type As String, ByVal procsTable As String) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT "
        szSql &= "A.MNF_CND_TAG, A.ACTUAL_MODEL "
        szSql &= String.Format("FROM MAT.{0} AS A ", procsTable)
        szSql &= "WHERE LOT_NO = '" & LotNo & "' "
        szSql &= "AND KOUTEI_CD = '" & procsCD & "' "
        szSql &= "AND TYPE = '" & type & "' "
        szSql &= "AND PROC_TIMES = ("
        szSql &= "  SELECT MAX(PROC_TIMES) "
        szSql &= String.Format("FROM MAT.{0} AS B ", procsTable)
        szSql &= "  WHERE A.LOT_NO = B.LOT_NO "
        szSql &= "  AND A.KOUTEI_CD = B.KOUTEI_CD "
        szSql &= "  AND A.TYPE = B.TYPE "
        szSql &= ")"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, LotNo)
        If IsNothing(dt) Then
            GetEquipResult = New DataTable
        Else
            GetEquipResult = dt
        End If
    End Function

    '装置条件取得
    Public Function GetEquipmentCondition(ByVal procCd As String, ByVal equipCondition As String) As DataTable
        Dim szSql As String = ""

        szSql &= "SELECT "
        szSql &= " BAKE_TEMPERATURE, BAKE_TIME "
        szSql &= "FROM "
        szSql &= "  PER.T_EQUIPMENT_CONDITIONS "
        szSql &= "WHERE "
        szSql &= " PROC_CD = '" & procCd & "' "
        szSql &= " AND EQUIPMENT_CONDITIONS = '" & equipCondition & "' ;"

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            GetEquipmentCondition = New DataTable
        Else
            GetEquipmentCondition = dt
        End If
    End Function

    ''' <summary>
    ''' bSiteに送信するClient情報をt_proc_cdから取得する
    ''' </summary>
    ''' <param name="procCd">画面ID</param>
    ''' <returns>Client文字列</returns>
    Public Function GetBsiteClientString(ByVal procCd As String) As String
        Dim retStr = String.Empty
        Dim szSql As String = ""

        szSql &= "SELECT "
        szSql &= " PROC_CD, CLIENT_CODE "
        szSql &= "FROM "
        szSql &= "  PER.T_PROC_CD "
        szSql &= "WHERE "
        szSql &= " PROC_CD = '" & procCd & "' " 'UPD MIAO 2018/10/17

        Dim dt = DBacs.ExecuteSql(szSql, -1)
        If Not IsNothing(dt) Then
            Dim getData = dt.AsEnumerable().FirstOrDefault(Function(x) procCd.Equals(x("PROC_CD")))
            'UPD 苗 2018/1/19 RSB側でATLASの設備の工程がA12が存在して、S121,S122工程用。
            'per.t_proc_cdにはA12を登録しないため、エラーが発生しないように対応。
            If Not IsNothing(getData) AndAlso Not IsDBNull(getData("CLIENT_CODE")) Then
                retStr = getData("CLIENT_CODE")
            End If
        End If
        Return retStr
    End Function


    '設備No取得
    Public Function getPreEquipId(ByVal szLotNo As String, ByVal szKouteiCd As String) As String
        Dim szSql As String = ""
        szSql &= "SELECT B.EQUIP_NO AS EQUIP_NO "
        szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD A "
        szSql &= "INNER JOIN KAD.T_EQUIP_REG B "
        szSql &= "On A.EQUIP_ID = B.EQUIP_NO " 'UPD 苗 2018/1/26 
        szSql &= "WHERE A.LOT_NO= ? "
        szSql &= "AND A.KOUTEI_CD= ? "
        szSql &= "AND A.TYPE = ? "

        Dim dt = DBacs.ExecuteSql(szSql, -1, szLotNo, szKouteiCd, TOTAL)
        If dt.Rows.Count > 0 Then
            For Each item In dt.Rows
                Return item("EQUIP_NO")
            Next
        End If
        Return String.Empty
    End Function
    'ADD 苗 2018/1/29 BEGIN
    'GroupKey範囲内の組立ロットは指定工程で一度完成したら、TrueをReturn。
    Public Function isWaferCaseChecked(ByVal szProcCD As String, ByVal szLotNo As String) As Boolean
        Dim szSql As String = ""
        szSql &= "SELECT MAX(H.TYPE) AS TYPE FROM MAT.L_SF_WORK_RSLT_HEAD H "
        szSql &= "WHERE H.KOUTEI_CD = ? AND H.LOT_NO IN ( "
        szSql &= "SELECT A.LOT_NO FROM PER.L_TAG_LOTDATA A "
        szSql &= "WHERE A.WAFER_LOTNO = ( "
        szSql &= "SELECT B.WAFER_LOTNO FROM PER.L_TAG_LOTDATA B "
        szSql &= "WHERE B.LOT_NO = ? )) AND TYPE <> '9' " 'UPD 苗 2018/4/2

        Dim dt = DBacs.ExecuteSql(szSql, -1, szProcCD, szLotNo)
        If IsDBNull(dt) OrElse IsDBNull(dt.Rows(0)("TYPE")) OrElse dt.Rows(0)("TYPE") = 1 Then
            Return False
        ElseIf dt.Rows(0)("TYPE") = 2 Or dt.Rows(0)("TYPE") = 3 Then
            Return True
        End If
        Return False

    End Function
    'ADD 苗 2018/1/29 END

    'ADD 苗 2018/2/7 BEGIN
    'lot keyNoからframe_id_use取得
    Public Function getframeIDUse(ByVal szLotNo As String) As String
        Dim szSql As String = ""
        szSql &= "SELECT FRAME_ID_USE "
        szSql &= "FROM PER.L_TAG_LOTDATA  "
        szSql &= "WHERE lot_no = '" & szLotNo & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsDBNull(dt.Rows(0)(0)) Then
            Return "0"
        Else
            Return dt.Rows(0)(0)
        End If
        Return "0"
    End Function
    'ADD 苗 2018/2/7 END

    'ADD 苗 2018/4/2 BEGIN
    Public Sub killProcess(procName As String)

        For Each proc In Process.GetProcesses

            If proc.ProcessName Like procName Then

                proc.Kill()
                Exit Sub
            End If

        Next

    End Sub
    'ADD 苗 2018/4/2 END

    'ADD 苗 2018/8/13 BEGIN
    ''' <summary>
    ''' 設備Lotの削除処理
    ''' </summary>
    ''' <param name="EquipNo">設備No</param>
    Public Sub delLotDataForEquipNo(ByRef EquipNo As String)

        Dim szSql As String = ""
        szSql &= "DELETE FROM PER.T_WORKING_LOT "
        szSql &= "WHERE EQUIP_NO = ? ;"
        DBacs.ExecuteUpdateSql(szSql, -1, EquipNo)

    End Sub
    'ADD 苗 2018/8/13 END

    Public Function getPKG(equip_no As String, PKG As String) As String
        Dim szSql As String = ""
        szSql &= "SELECT PKG "
        szSql &= "FROM per.t_last_PKG  "
        szSql &= "WHERE equip_no = '" & equip_no & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If dt.Rows.Count = 0 Then
            szSql = ""
            szSql &= "INSERT into per.t_last_PKG  (equip_no,PKG) VALUES (?, ?)  "
            DBacs.ExecuteUpdateSql(szSql, -1, equip_no, PKG)
        Else
            Return dt.Rows(0)(0)
        End If
        Return "0"
    End Function
    Public Sub setPKG(equip_no As String, PKG As String)
        Dim szSql As String = ""

        szSql &= "UPDATE per.t_last_PKG "

        szSql &= "set PKG ='" & PKG & "' "
        szSql &= "WHERE equip_no='" & equip_no & "' "
        DBacs.ExecuteUpdateSql(szSql, -1)

    End Sub
    'フレームの情報を取得する
    Public Function getFrameCount(ByVal szLotNo As String, szKoutei As String) As DataTable
        Dim szSql As String = ""

        szSql = "SELECT COUNT(*), SUM(CH_COUNT), SUM(CN_COUNT)"
        szSql = szSql & " FROM TRA.L_FRAME_INFO"
        szSql = szSql & " WHERE LOT_NO = '" & szLotNo & "'"
        szSql = szSql & " AND KOUTEI_CODE = '" & szKoutei & "'"
        szSql = szSql & " AND ( CH_COUNT > 0 OR CN_COUNT > 0 ) AND FRAME_COND > 0"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            getFrameCount = New DataTable
        Else
            getFrameCount = dt
        End If

    End Function
    'PKG_PER_FRMの情報を取得する
    Public Function getPKGPerFrame(ByVal szLotNo As String) As Integer
        Dim szSql As String = ""

        szSql = "SELECT PKG_PER_FRM FROM TRA.L_LOT_INFO WHERE KEY_NO = '" & szLotNo & "' "

        Dim ResDt As DataTable = DBacs.ExecuteSql(szSql, -1)

        Dim lPkg As Integer = 0
        If ResDt.Rows.Count > 0 Then
            If IsDBNull(ResDt.Rows(0).Item(0)) = False Then
                lPkg = CLng(ResDt.Rows(0).Item(0))
            End If
        End If

        Return lPkg

    End Function

    'FrameInfoCountの情報を取得する
    Public Function getTotalNgFrameCount(ByVal szLotNo As String, szKoutei As String, IPkg As Integer) As Integer
        Dim szSql As String = ""

        szSql = "SELECT COUNT(*)"
        szSql = szSql & " FROM TRA.L_FRAME_INFO"
        szSql = szSql & " WHERE LOT_NO = '" & szLotNo & "'"
        szSql = szSql & " AND KOUTEI_CODE = '" & szKoutei & "'"
        szSql = szSql & " AND CH_COUNT <> ? "
        szSql = szSql & " AND CH_COUNT > 0"


        Dim ResDt As DataTable = DBacs.ExecuteSql(szSql, -1, IPkg)

        Dim intCount As Integer = 0
        If ResDt.Rows.Count > 0 Then
            If IsDBNull(ResDt.Rows(0).Item(0)) = False Then
                intCount = CLng(ResDt.Rows(0).Item(0))
            End If
        End If

        Return intCount

    End Function
    'ADD MIAO 2018/8/24 BEGIN
    'Resinチェック：LastのResinが存在しない時、該当Resinを保存します。（次回利用）
    '　　　　　　　 LastのResinが存在する時、LastのResinと今回のResinによって、検索する
    '　　　　　　　 　検索結果がないとき、"0"をRリターンする。
    '　　　　　　　　 検索結果がある時、エラーメッセージのParamをリターンする
    Public Function getResinCheckParam(equip_no As String, newResin As String) As String
        Dim szSql As String = ""
        Dim oldResin As String = ""
        'LastのResinを取得する
        szSql &= "SELECT Resin "
        szSql &= "FROM per.t_last_resin  "
        szSql &= "WHERE equip_no = '" & equip_no & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If dt.Rows.Count = 0 Then
            'LastのResinが存在しない時、該当Resinを保存します。
            szSql = ""
            szSql &= "INSERT into per.t_last_resin  (equip_no,Resin) VALUES (?, ?)  "
            DBacs.ExecuteUpdateSql(szSql, -1, equip_no, newResin)
        Else
            'LastのResinが存在する時、LastのResinと今回のResinによって、検索する
            oldResin = DBNullTOblank(dt.Rows(0)(0)) 'UPD Miao 2018/10/23
            szSql = ""
            szSql &= "SELECT Param "
            szSql &= "FROM per.t_resinclear_mst  "
            szSql &= "WHERE oldresin = '" & oldResin & "' "
            szSql &= "AND newResin = '" & newResin & "' "

            Dim dtParam As DataTable = DBacs.ExecuteSql(szSql, -1)
            If dtParam.Rows.Count = 0 Then
                '検索結果がないとき、"0"をRリターンする。
                Return "0"
            End If
            '検索結果がある時、エラーメッセージのParamをリターンする
            Return dtParam.Rows(0)(0)
        End If
        Return "0"
    End Function
    'LastのResinを設定
    Public Sub SetLastResin(equip_no As String, Resin As String)
        Dim szSql As String = ""

        szSql &= "UPDATE per.t_last_resin "
        szSql &= "set Resin ='" & Resin & "' "
        szSql &= "WHERE equip_no='" & equip_no & "' "
        DBacs.ExecuteUpdateSql(szSql, -1)

    End Sub
    ' << 20180309 大賀 着工中のデータをWBラック管理テーブルから取得するように修正
    'ADD MIAO 2018/10/17 Begin
    Public Function DBNullTOblank(obj As Object) As String
        DBNullTOblank = IIf(IsDBNull(obj), "", obj)
    End Function
    'ADD MIAO 2018/10/17 END

    'ADD MIAO 2018/11/08 Begin
    Public Function getEquipStatus(equipID As String) As String
        Dim szSql As String = ""
        Dim rtn As String = ""
        szSql &= "SELECT B.ALL_ILOCK_STS,B.M_ILOCK_STS,B.R_ILOCK_STS,B.F_ILOCK_STS,"
        szSql &= "B.A_ILOCK_STS, B.U_ILOCK_STS, B.V_ILOCK_STS, B.D_ILOCK_STS, B.S_ILOCK_STS, B.T_ILOCK_STS, B.L_ILOCK_STS "
        szSql &= "FROM KAD.T_EQUIP_REG A INNER JOIN KAD.S_EQUIP B "
        szSql &= "On A.sys_equip_id = B.sys_equip_id "
        szSql &= "WHERE A.equip_id='" & equipID & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) = True OrElse dt.Rows.Count = 0 Then
            rtn = "0"
        Else
            If dt.Rows(0)("ALL_ILOCK_STS") = "0" Then
                rtn = "0"
            Else
                rtn = vbCrLf
                If dt.Rows(0)("M_ILOCK_STS") <> "0" Then
                    rtn &= "MONITORING ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("R_ILOCK_STS") <> "0" Then
                    rtn &= "recipe照合 ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("F_ILOCK_STS") <> "0" Then
                    rtn &= "成型 MONITOR ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("A_ILOCK_STS") <> "0" Then

                End If
                If dt.Rows(0)("U_ILOCK_STS") <> "0" Then
                    rtn &= "US MONITOR ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("V_ILOCK_STS") <> "0" Then
                    rtn &= "震动 MONITOR ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("D_ILOCK_STS") <> "0" Then

                End If
                If dt.Rows(0)("S_ILOCK_STS") <> "0" Then
                    rtn &= "保全系统 ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("T_ILOCK_STS") <> "0" Then
                    rtn &= "始业点检系统 ： 锁定 " & vbCrLf
                End If
                If dt.Rows(0)("L_ILOCK_STS") <> "0" Then
                    rtn &= "SF系统 ： 锁定 " & vbCrLf
                End If

            End If
        End If
        Return rtn
    End Function
    'ADD MIAO 2018/11/08 END

    'ADD MIAO 2019/10/01 Begin
    ''' <summary>
    ''' ソケット通信フラグの取得
    ''' </summary>
    ''' <param name="equipId"></param>
    ''' <returns></returns>
    Public Function getSocketFlag(ByVal equipId As String) As String
        Dim szSql As String = ""

        szSql &= "Select SOCKET_FLAG "
        szSql &= "FROM KAD.T_EQUIP_REG  "
        szSql &= "WHERE EQUIP_ID = ? "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, equipId)
        If dt.Rows.Count > 0 Then
            If IsDBNull(dt.Rows(0)(0)) Then
                Return "0"
            Else
                Return dt.Rows(0)(0)
            End If
            Return "0"
        Else
            Return "0"
        End If

    End Function

    Public Function GetRackFlowFlag(ByVal procCode As String) As Integer
        Dim szSql As String = ""

        szSql &= "Select "
        szSql &= "PROC_CD, RACK_FLOW_FLAG "
        szSql &= "FROM PER.T_PROC_CD "
        szSql &= "WHERE PROC_CD = ? "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, procCode)
        Dim item = dt.AsEnumerable.FirstOrDefault()
        If IsNothing(item) Then
            GetRackFlowFlag = 0
        Else
            GetRackFlowFlag = dt(0)("RACK_FLOW_FLAG")
        End If
    End Function

    Public Sub saveAProcResultForRC(SprocCD As String, AProcCD As String, Type As String, Lotno As String, Optional ByVal ht As Hashtable = Nothing)
        Try


            'DBacs.BeginTransaction()
            '------------------HEAD------------------
            Dim szSql As String = ""
            szSql &= "DELETE MAT.L_SF_WORK_RSLT_HEAD "
            szSql &= " WHERE LOT_NO ='" & Lotno & "' and KOUTEI_CD = '" & AProcCD & "' AND TYPE = '" & Type & "'"
            DBacs.ExecuteUpdateSql(szSql, -1)

            szSql = ""
            szSql &= "INSERT INTO MAT.L_SF_WORK_RSLT_HEAD( "
            szSql &= "LOT_NO,KOUTEI_CD,TYPE,PROC_TIMES,OPERATOR"
            szSql &= ",OPT_TIME,EQUIP_ID,PROD_NAME,DIFF_LOT,PB_LAYOUT"
            szSql &= ",SHAPE,BEGIN_TIME,BEGIN_OPT,INPUT_QTY,INPUTFRM_QTY"
            szSql &= ",INPUTCROSS_QTY,COMPLETE_TIME,COMPLETE_OPT,COMPLETE_QTY"
            szSql &= ",DEFECT_QTY,FRAME_QTY,CROSS_QTY,IS_CHECKED,Q_FLAG"
            szSql &= ",UPDATE_TIME,INPUTCROSS_FRMQTY,CROSS_FRMQTY,INPUT_WAFER_QTY,WAFER_QTY) "
            szSql &= "SELECT "
            szSql &= "  LOT_NO"
            szSql &= "  , '" & AProcCD & "' AS KOUTEI_CD"
            szSql &= "  , '" & Type & "' AS TYPE"
            szSql &= "  , 1 AS PROC_TIMES"
            szSql &= "  , OPERATOR, now(), EQUIP_ID, PROD_NAME"
            szSql &= "  , DIFF_LOT, PB_LAYOUT, SHAPE, now()"
            szSql &= "  , BEGIN_OPT, INPUT_QTY, INPUTFRM_QTY, INPUTCROSS_QTY, now(), COMPLETE_OPT"
            If IsNothing(ht) Then
                szSql &= "  , COMPLETE_QTY, DEFECT_QTY, FRAME_QTY, CROSS_QTY"
            Else
                szSql &= "  ," & Val(ht("totalOkCnt").ToString()) & "," & Val(ht("totalNgCnt").ToString()） & "," & Val(ht("frameCnt").ToString()) & "," & Val(ht("totalCrossCnt").ToString())
            End If
            szSql &= "  , IS_CHECKED, Q_FLAG"
            szSql &= "  , UPDATE_TIME, INPUTCROSS_FRMQTY, "
            If IsNothing(ht) Then
                szSql &= "  CROSS_FRMQTY"
            Else
                szSql &= Val(ht("crossPcbCnt").ToString())

            End If

            szSql &= "  , INPUT_WAFER_QTY, WAFER_QTY  "
            szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
            szSql &= "WHERE LOT_NO='" & Lotno & "' "
            szSql &= "AND KOUTEI_CD='" & SprocCD & "' "
            szSql &= "AND TYPE='3' "
            szSql &= "AND PROC_TIMES=(SELECT MAX(PROC_TIMES) "
            szSql &= "FROM MAT.L_SF_WORK_RSLT_HEAD "
            szSql &= "WHERE LOT_NO='" & Lotno & "' "
            szSql &= "AND KOUTEI_CD='" & SprocCD & "' "
            szSql &= "AND TYPE='3' )"
            DBacs.ExecuteUpdateSql(szSql, -1)
            '------------------履歴------------------
            szSql = ""

            szSql &= "DELETE MAT.L_SF_WORK_RSLT_" & AProcCD
            szSql &= " WHERE LOT_NO ='" & Lotno & "' AND TYPE = '" & Type & "'"
            DBacs.ExecuteUpdateSql(szSql, -1)
            szSql = ""

            szSql &= "INSERT INTO MAT.L_SF_WORK_RSLT_" & AProcCD & "(LOT_NO, KOUTEI_CD, TYPE, PROC_TIMES,"
            szSql &= "MNF_CND_TAG, MNF_CND_TAG_FLG, SEQ, MNF_CONDITION, ACTUAL_MODEL,"
            szSql &= "MANAGEMENT_NO, MATERIAL_LOT, LIMIT_TIME, UPDATE_TIME) "
            szSql &= "SELECT "
            szSql &= "LOT_NO,"
            szSql &= "'" & AProcCD & "' AS KOUTEI_CD,"
            szSql &= "'" & Type & "' AS TYPE,"
            szSql &= "1 AS PROC_TIMES,"
            szSql &= "MNF_CND_TAG,MNF_CND_TAG_FLG,SEQ,MNF_CONDITION,ACTUAL_MODEL,MANAGEMENT_NO,MATERIAL_LOT,LIMIT_TIME,now() "
            szSql &= "FROM  MAT.L_SF_WORK_RSLT_" & SprocCD & " WHERE LOT_NO='" & Lotno & "' "
            szSql &= "AND TYPE='3' AND PROC_TIMES =("
            szSql &= "SELECT MAX(PROC_TIMES) FROM MAT.L_SF_WORK_RSLT_" & SprocCD & " WHERE LOT_NO='" & Lotno & "' AND TYPE='3')"
            DBacs.ExecuteUpdateSql(szSql, -1)
            'DBacs.CommitTransaction()
        Catch ex As Exception
            MsgBox("A工程履历保存失败！")
            ' DBacs.RollbackTransaction()
        End Try
    End Sub
    'ADD MIAO 2019/10/01 END

    Public Sub setFrameIDUse(lotNo As String, frameIDUse As Integer)
        Dim szSql As String = ""

        szSql &= "UPDATE per.L_tag_Lotdata "
        szSql &= "set Frame_ID_Use=" & frameIDUse
        szSql &= "WHERE LOT_NO='" & lotNo & "' "
        DBacs.ExecuteUpdateSql(szSql, -1)
    End Sub

    Public Function getSeries(ByVal equipNo As String) As String
        Dim szSql As String = ""
        Dim rtn As String = ""

        szSql &= "SELECT Series from KAD.T_EQUIP_REG where EQUIP_NO=? "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, equipNo)
        If dt.Rows.Count > 0 Then
            rtn = DBNullTOblank(dt.Rows(0)(0))
        End If
        Return rtn

    End Function

    Public Function getEQUIP_SERIES(equipNo As String, _RECIPE_NAME As String) As String
        Dim szSql As String = ""
        Dim rtn As String = ""

        szSql &= "SELECT RCP_SERIES FROM KAD.T_EQUIP_REG WHERE EQUIP_NO = ? "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, equipNo)
        If dt.Rows.Count > 0 Then
            szSql = "SELECT DISTINCT RECIPE_NAME FROM RCP.T_DB_PARA_VERIFY_MASTER WHERE
                     RECIPE_NAME like '%" & _RECIPE_NAME & "' AND EQUIP_SERIES = ? "
            Dim dt1 As DataTable = DBacs.ExecuteSql(szSql, -1, dt.Rows(0)(0))
            If dt1.Rows.Count = 1 Then
                rtn = dt1.Rows(0)("RECIPE_NAME")
            ElseIf dt1.Rows.Count = 0 Then
                rtn = ""
            ElseIf dt1.Rows.Count > 1 Then
                rtn = "too Much"
            End If
            'rtn = dt1.Rows(0)("RECIPE_NAME")
        End If
        Return rtn

    End Function
End Class



